C#实现设置电脑显示器参数

目录
  • 实践过程
    • 效果
    • 代码

实践过程

效果

代码

public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
    }
    string MaxValue;//显示器支持的最大刷新率
    string MinValue;//显示器支持的最小刷新率
    string NowValue;//当前刷新率
    bool flag = true;

    public const uint WM_SYSCOMMAND = 0x0112;
    public const uint SC_MONITORPOWER = 0xF170;
    [DllImport("user32")]
    public static extern IntPtr SendMessage(IntPtr hWnd, uint wMsg, uint wParam, int lParam);

    public enum DMDO
    {
        DEFAULT = 0,
        D90 = 1,
        D180 = 2,
        D270 = 3
    }

    [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
    struct DEVMODE
    {
        public const int DM_DISPLAYFREQUENCY = 0x400000;
        public const int DM_PELSWIDTH = 0x80000;
        public const int DM_PELSHEIGHT = 0x100000;
        public const int DM_BITSPERPEL = 262144;
        private const int CCHDEVICENAME = 32;
        private const int CCHFORMNAME = 32;
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = CCHDEVICENAME)]
        public string dmDeviceName;
        public short dmSpecVersion;
        public short dmDriverVersion;
        public short dmSize;
        public short dmDriverExtra;
        public int dmFields;
        public int dmPositionX;
        public int dmPositionY;
        public DMDO dmDisplayOrientation;
        public int dmDisplayFixedOutput;
        public short dmColor;
        public short dmDuplex;
        public short dmYResolution;
        public short dmTTOption;
        public short dmCollate;
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = CCHFORMNAME)]
        public string dmFormName;
        public short dmLogPixels;
        public int dmBitsPerPel;
        public int dmPelsWidth;
        public int dmPelsHeight;
        public int dmDisplayFlags;
        public int dmDisplayFrequency;
        public int dmICMMethod;
        public int dmICMIntent;
        public int dmMediaType;
        public int dmDitherType;
        public int dmReserved1;
        public int dmReserved2;
        public int dmPanningWidth;
        public int dmPanningHeight;
    }

    [DllImport("user32.dll", CharSet = CharSet.Auto)]
    static extern int ChangeDisplaySettings([In] ref DEVMODE lpDevMode, int dwFlags);

    private void Form1_Load(object sender, EventArgs e)
    {
        groupBox5.Text = "当前时间:" + DateTime.Now.ToString();
        ManagementObjectSearcher searcher = new ManagementObjectSearcher("select * from Win32_VideoController");
        foreach(ManagementObject myobject in searcher.Get() )
        {
            string Vname = myobject["Name"].ToString();
            if (Vname.Length >40)
            {
                string a = Vname.Substring(0,45);
                string b = Vname.Substring(46);
                lblInfo.Text = a + "\n" + b;
            }
            else
            {
                lblInfo.Text = Vname;
            }
            string colorValue = myobject["CurrentNumberOfColors"].ToString();
            if (colorValue == "65536")
            {
                comboBox1.SelectedIndex = 0;
            }
            else
            {
                comboBox1.SelectedIndex = 1;
            }
            MaxValue=myobject["MaxRefreshRate"].ToString();
            if (Convert.ToInt32(MaxValue) > 85)
                MaxValue = "85";
            MinValue = myobject["MinRefreshRate"].ToString();
            NowValue=myobject["CurrentRefreshRate"].ToString();
            AddHZ();
            GetDis();
            ChangeDis(1);
        }

    }
    int dWidth = 0;
    int dHeight = 0;
    private void GetDis()//获取分辨率
    {
        Size s = SystemInformation.PrimaryMonitorSize;
        dWidth = s.Width;
        dHeight = s.Height;
        lblDisInfo.Text = dWidth.ToString() + " × " + dHeight.ToString() + " 像素";
    }

    private void ChangeDis(int i)//变换分辨率
    {
        int dValue;
        dValue = trackBar1.Value;
        if (i == 0)
        {
            switch (dValue)
            {
                case 0: dWidth = 800; dHeight = 600; break;
                case 1: dWidth = 1024; dHeight = 768; break;
                case 2: dWidth = 1152; dHeight = 864; break;
                case 3: dWidth = 1280; dHeight = 600; break;
                case 4: dWidth = 1280; dHeight = 720; break;
                case 5: dWidth = 1280; dHeight = 768; break;
                case 6: dWidth = 1280; dHeight = 760; break;
                case 7: dWidth = 1280; dHeight = 1024; break;
                case 8: dWidth = 1400; dHeight = 1050; break;
                case 9: dWidth = 1600; dHeight = 900; break;
                case 10: dWidth = 1600; dHeight = 1200; break;
            }
            lblDisInfo.Text = dWidth.ToString() + " × " + dHeight.ToString() + " 像素";
        }
        else
        {
            int dSum=dWidth+dHeight;
            switch (dSum)
            {
                case 1400: trackBar1.Value = 0; break;
                case 1792: trackBar1.Value = 1; break;
                case 2016: trackBar1.Value = 2; break;
                case 1880: trackBar1.Value = 3; break;
                case 2000: trackBar1.Value = 4; break;
                case 2048: trackBar1.Value = 5; break;
                case 2240: trackBar1.Value = 6; break;
                case 2304: trackBar1.Value = 7; break;
                case 2450: trackBar1.Value = 8; break;
                case 2500: trackBar1.Value = 9; break;
                case 2800: trackBar1.Value = 10; break;
            }
        }
    }

    private void AddHZ()
    {
        int[] hz = new int[] { 60, 70, 75, 85, 100, 120 };
        comboBox2.Items.Clear();
        if (checkBox1.Checked)
        {
            for (int i = 0; i < hz.Length; i++)
            {
                if (hz[i] <= Convert.ToInt32(MaxValue))
                {
                    comboBox2.Items.Add(hz[i].ToString() + "赫兹");
                }
            }
            comboBox2.Text = NowValue + "赫兹";
        }
        else
        {
            for (int j = 0; j < hz.Length; j++)
            {
                comboBox2.Items.Add(hz[j].ToString() + "赫兹");
            }
            comboBox2.Text = NowValue + "赫兹";
        }
    }

    private void checkBox1_CheckedChanged(object sender, EventArgs e)
    {
        AddHZ();
    }

    private void button2_Click(object sender, EventArgs e)
    {
        Application.Exit();
    }

    private void trackBar1_Scroll(object sender, EventArgs e)
    {
        ChangeDis(0);
    }

    private void radioButton1_CheckedChanged(object sender, EventArgs e)
    {
        if (radioButton1.Checked)
        {
            groupBox1.Enabled = true;
            groupBox2.Enabled = true;
            groupBox3.Enabled = true;
            groupBox4.Enabled = true;
        }
        else
        {
            groupBox1.Enabled = false;
            groupBox2.Enabled = false;
            groupBox3.Enabled = false;
            groupBox4.Enabled = false;
        }
    }

    private void radioButton2_CheckedChanged(object sender, EventArgs e)
    {
        if (radioButton2.Checked)
        {
            groupBox5.Enabled = true;
        }
        else
        {
            groupBox5.Enabled = false;
        }
    }

    private void button1_Click(object sender, EventArgs e)
    {
        if (radioButton1.Checked)//设置分辨率、颜色质量、刷新率
        {
            long RetVal = 0;
            DEVMODE dm = new DEVMODE();
            dm.dmSize = (short)Marshal.SizeOf(typeof(DEVMODE));
            dm.dmPelsWidth = dWidth;//宽
            dm.dmPelsHeight = dHeight;//高
            int f =Convert.ToInt32(comboBox2.Text.Trim().Remove(comboBox2.Text.Trim().Length-2));
            dm.dmDisplayFrequency = f;//刷新率
            if (comboBox1.SelectedIndex == 0)
                dm.dmBitsPerPel = 16;
            else
                dm.dmBitsPerPel = 32;
            dm.dmFields = DEVMODE.DM_PELSWIDTH | DEVMODE.DM_PELSHEIGHT | DEVMODE.DM_DISPLAYFREQUENCY | DEVMODE.DM_BITSPERPEL;
            RetVal = ChangeDisplaySettings(ref dm, 0);
        }
        if (radioButton2.Checked)//关闭显示器
        {
            timer1.Start();
            this.Close();
        }
    }

    private void timer1_Tick(object sender, EventArgs e)
    {
        if (dateTimePicker1.Text == DateTime.Now.ToLongTimeString())
        {
            SendMessage(this.Handle, WM_SYSCOMMAND, SC_MONITORPOWER, 2);
            timer1.Stop();
        }
    }

    private void Form1_FormClosing(object sender, FormClosingEventArgs e)
    {
        this.Hide();
        if (flag)
        {
            e.Cancel = true;
        }
    }

    private void 退出ToolStripMenuItem_Click(object sender, EventArgs e)
    {
        flag = false;
        Application.Exit();
    }

    private void 显示ToolStripMenuItem_Click(object sender, EventArgs e)
    {
        this.Show();
    }

    private void notifyIcon1_MouseDoubleClick(object sender, MouseEventArgs e)
    {
        this.Show();
    }

    private void timer2_Tick(object sender, EventArgs e)
    {
        groupBox5.Text = "当前时间:" + DateTime.Now.ToString();
    }
}
partial class Form1
{
    /// <summary>
    /// 必需的设计器变量。
    /// </summary>
    private System.ComponentModel.IContainer components = null;

    /// <summary>
    /// 清理所有正在使用的资源。
    /// </summary>
    /// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
    protected override void Dispose(bool disposing)
    {
        if (disposing && (components != null))
        {
            components.Dispose();
        }
        base.Dispose(disposing);
    }

    #region Windows 窗体设计器生成的代码

    /// <summary>
    /// 设计器支持所需的方法 - 不要
    /// 使用代码编辑器修改此方法的内容。
    /// </summary>
    private void InitializeComponent()
    {
        this.components = new System.ComponentModel.Container();
        System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1));
        this.groupBox1 = new System.Windows.Forms.GroupBox();
        this.lblDisInfo = new System.Windows.Forms.Label();
        this.label2 = new System.Windows.Forms.Label();
        this.label1 = new System.Windows.Forms.Label();
        this.trackBar1 = new System.Windows.Forms.TrackBar();
        this.groupBox2 = new System.Windows.Forms.GroupBox();
        this.lblInfo = new System.Windows.Forms.Label();
        this.groupBox3 = new System.Windows.Forms.GroupBox();
        this.comboBox1 = new System.Windows.Forms.ComboBox();
        this.groupBox4 = new System.Windows.Forms.GroupBox();
        this.checkBox1 = new System.Windows.Forms.CheckBox();
        this.comboBox2 = new System.Windows.Forms.ComboBox();
        this.groupBox5 = new System.Windows.Forms.GroupBox();
        this.dateTimePicker1 = new System.Windows.Forms.DateTimePicker();
        this.label4 = new System.Windows.Forms.Label();
        this.button1 = new System.Windows.Forms.Button();
        this.button2 = new System.Windows.Forms.Button();
        this.radioButton1 = new System.Windows.Forms.RadioButton();
        this.radioButton2 = new System.Windows.Forms.RadioButton();
        this.timer1 = new System.Windows.Forms.Timer(this.components);
        this.notifyIcon1 = new System.Windows.Forms.NotifyIcon(this.components);
        this.contextMenuStrip1 = new System.Windows.Forms.ContextMenuStrip(this.components);
        this.显示ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
        this.退出ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
        this.timer2 = new System.Windows.Forms.Timer(this.components);
        this.groupBox1.SuspendLayout();
        ((System.ComponentModel.ISupportInitialize)(this.trackBar1)).BeginInit();
        this.groupBox2.SuspendLayout();
        this.groupBox3.SuspendLayout();
        this.groupBox4.SuspendLayout();
        this.groupBox5.SuspendLayout();
        this.contextMenuStrip1.SuspendLayout();
        this.SuspendLayout();
        //
        // groupBox1
        //
        this.groupBox1.Controls.Add(this.lblDisInfo);
        this.groupBox1.Controls.Add(this.label2);
        this.groupBox1.Controls.Add(this.label1);
        this.groupBox1.Controls.Add(this.trackBar1);
        this.groupBox1.Location = new System.Drawing.Point(11, 96);
        this.groupBox1.Name = "groupBox1";
        this.groupBox1.Size = new System.Drawing.Size(161, 81);
        this.groupBox1.TabIndex = 0;
        this.groupBox1.TabStop = false;
        this.groupBox1.Text = "屏幕分辨率";
        //
        // lblDisInfo
        //
        this.lblDisInfo.AutoSize = true;
        this.lblDisInfo.Location = new System.Drawing.Point(36, 57);
        this.lblDisInfo.Name = "lblDisInfo";
        this.lblDisInfo.Size = new System.Drawing.Size(41, 12);
        this.lblDisInfo.TabIndex = 3;
        this.lblDisInfo.Text = "label3";
        //
        // label2
        //
        this.label2.AutoSize = true;
        this.label2.Location = new System.Drawing.Point(134, 29);
        this.label2.Name = "label2";
        this.label2.Size = new System.Drawing.Size(17, 12);
        this.label2.TabIndex = 2;
        this.label2.Text = "多";
        //
        // label1
        //
        this.label1.AutoSize = true;
        this.label1.Location = new System.Drawing.Point(15, 29);
        this.label1.Name = "label1";
        this.label1.Size = new System.Drawing.Size(17, 12);
        this.label1.TabIndex = 1;
        this.label1.Text = "少";
        //
        // trackBar1
        //
        this.trackBar1.AutoSize = false;
        this.trackBar1.Location = new System.Drawing.Point(33, 26);
        this.trackBar1.Name = "trackBar1";
        this.trackBar1.Size = new System.Drawing.Size(95, 23);
        this.trackBar1.TabIndex = 0;
        this.trackBar1.Scroll += new System.EventHandler(this.trackBar1_Scroll);
        //
        // groupBox2
        //
        this.groupBox2.Controls.Add(this.lblInfo);
        this.groupBox2.Location = new System.Drawing.Point(12, 36);
        this.groupBox2.Name = "groupBox2";
        this.groupBox2.Size = new System.Drawing.Size(328, 53);
        this.groupBox2.TabIndex = 2;
        this.groupBox2.TabStop = false;
        this.groupBox2.Text = "显示设备";
        //
        // lblInfo
        //
        this.lblInfo.AutoSize = true;
        this.lblInfo.Location = new System.Drawing.Point(10, 20);
        this.lblInfo.Name = "lblInfo";
        this.lblInfo.Size = new System.Drawing.Size(41, 12);
        this.lblInfo.TabIndex = 0;
        this.lblInfo.Text = "label3";
        //
        // groupBox3
        //
        this.groupBox3.Controls.Add(this.comboBox1);
        this.groupBox3.Location = new System.Drawing.Point(178, 96);
        this.groupBox3.Name = "groupBox3";
        this.groupBox3.Size = new System.Drawing.Size(161, 81);
        this.groupBox3.TabIndex = 3;
        this.groupBox3.TabStop = false;
        this.groupBox3.Text = "颜色质量";
        //
        // comboBox1
        //
        this.comboBox1.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
        this.comboBox1.FormattingEnabled = true;
        this.comboBox1.Items.AddRange(new object[] {
        "中(16位)",
        "最高(32位)"});
        this.comboBox1.Location = new System.Drawing.Point(7, 31);
        this.comboBox1.Name = "comboBox1";
        this.comboBox1.Size = new System.Drawing.Size(148, 20);
        this.comboBox1.TabIndex = 0;
        //
        // groupBox4
        //
        this.groupBox4.Controls.Add(this.checkBox1);
        this.groupBox4.Controls.Add(this.comboBox2);
        this.groupBox4.Location = new System.Drawing.Point(12, 184);
        this.groupBox4.Name = "groupBox4";
        this.groupBox4.Size = new System.Drawing.Size(327, 85);
        this.groupBox4.TabIndex = 4;
        this.groupBox4.TabStop = false;
        this.groupBox4.Text = "设置刷新频率";
        //
        // checkBox1
        //
        this.checkBox1.AutoSize = true;
        this.checkBox1.Checked = true;
        this.checkBox1.CheckState = System.Windows.Forms.CheckState.Checked;
        this.checkBox1.Location = new System.Drawing.Point(7, 56);
        this.checkBox1.Name = "checkBox1";
        this.checkBox1.Size = new System.Drawing.Size(180, 16);
        this.checkBox1.TabIndex = 1;
        this.checkBox1.Text = "隐藏该显示器无法显示的模式";
        this.checkBox1.UseVisualStyleBackColor = true;
        this.checkBox1.CheckedChanged += new System.EventHandler(this.checkBox1_CheckedChanged);
        //
        // comboBox2
        //
        this.comboBox2.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
        this.comboBox2.FormattingEnabled = true;
        this.comboBox2.Items.AddRange(new object[] {
        "60赫兹",
        "70赫兹",
        "75赫兹",
        "85赫兹",
        "100赫兹",
        "120赫兹"});
        this.comboBox2.Location = new System.Drawing.Point(6, 20);
        this.comboBox2.Name = "comboBox2";
        this.comboBox2.Size = new System.Drawing.Size(315, 20);
        this.comboBox2.TabIndex = 0;
        //
        // groupBox5
        //
        this.groupBox5.Controls.Add(this.dateTimePicker1);
        this.groupBox5.Controls.Add(this.label4);
        this.groupBox5.Enabled = false;
        this.groupBox5.Location = new System.Drawing.Point(12, 296);
        this.groupBox5.Name = "groupBox5";
        this.groupBox5.Size = new System.Drawing.Size(328, 65);
        this.groupBox5.TabIndex = 5;
        this.groupBox5.TabStop = false;
        //
        // dateTimePicker1
        //
        this.dateTimePicker1.Checked = false;
        this.dateTimePicker1.Format = System.Windows.Forms.DateTimePickerFormat.Time;
        this.dateTimePicker1.Location = new System.Drawing.Point(94, 24);
        this.dateTimePicker1.Name = "dateTimePicker1";
        this.dateTimePicker1.ShowCheckBox = true;
        this.dateTimePicker1.ShowUpDown = true;
        this.dateTimePicker1.Size = new System.Drawing.Size(118, 21);
        this.dateTimePicker1.TabIndex = 1;
        //
        // label4
        //
        this.label4.AutoSize = true;
        this.label4.Location = new System.Drawing.Point(11, 28);
        this.label4.Name = "label4";
        this.label4.Size = new System.Drawing.Size(77, 12);
        this.label4.TabIndex = 0;
        this.label4.Text = "关闭显示器:";
        //
        // button1
        //
        this.button1.Location = new System.Drawing.Point(84, 372);
        this.button1.Name = "button1";
        this.button1.Size = new System.Drawing.Size(75, 23);
        this.button1.TabIndex = 6;
        this.button1.Text = "确定";
        this.button1.UseVisualStyleBackColor = true;
        this.button1.Click += new System.EventHandler(this.button1_Click);
        //
        // button2
        //
        this.button2.Location = new System.Drawing.Point(177, 372);
        this.button2.Name = "button2";
        this.button2.Size = new System.Drawing.Size(75, 23);
        this.button2.TabIndex = 7;
        this.button2.Text = "取消";
        this.button2.UseVisualStyleBackColor = true;
        this.button2.Click += new System.EventHandler(this.button2_Click);
        //
        // radioButton1
        //
        this.radioButton1.AutoSize = true;
        this.radioButton1.Checked = true;
        this.radioButton1.Location = new System.Drawing.Point(11, 12);
        this.radioButton1.Name = "radioButton1";
        this.radioButton1.Size = new System.Drawing.Size(71, 16);
        this.radioButton1.TabIndex = 8;
        this.radioButton1.TabStop = true;
        this.radioButton1.Text = "基本设置";
        this.radioButton1.UseVisualStyleBackColor = true;
        this.radioButton1.CheckedChanged += new System.EventHandler(this.radioButton1_CheckedChanged);
        //
        // radioButton2
        //
        this.radioButton2.AutoSize = true;
        this.radioButton2.Location = new System.Drawing.Point(11, 278);
        this.radioButton2.Name = "radioButton2";
        this.radioButton2.Size = new System.Drawing.Size(71, 16);
        this.radioButton2.TabIndex = 9;
        this.radioButton2.Text = "电源设置";
        this.radioButton2.UseVisualStyleBackColor = true;
        this.radioButton2.CheckedChanged += new System.EventHandler(this.radioButton2_CheckedChanged);
        //
        // timer1
        //
        this.timer1.Interval = 1000;
        this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
        //
        // notifyIcon1
        //
        this.notifyIcon1.ContextMenuStrip = this.contextMenuStrip1;
        this.notifyIcon1.Icon = ((System.Drawing.Icon)(resources.GetObject("notifyIcon1.Icon")));
        this.notifyIcon1.Text = "显示器控制";
        this.notifyIcon1.Visible = true;
        this.notifyIcon1.MouseDoubleClick += new System.Windows.Forms.MouseEventHandler(this.notifyIcon1_MouseDoubleClick);
        //
        // contextMenuStrip1
        //
        this.contextMenuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
        this.显示ToolStripMenuItem,
        this.退出ToolStripMenuItem});
        this.contextMenuStrip1.Name = "contextMenuStrip1";
        this.contextMenuStrip1.Size = new System.Drawing.Size(95, 48);
        //
        // 显示ToolStripMenuItem
        //
        this.显示ToolStripMenuItem.Name = "显示ToolStripMenuItem";
        this.显示ToolStripMenuItem.Size = new System.Drawing.Size(94, 22);
        this.显示ToolStripMenuItem.Text = "显示";
        this.显示ToolStripMenuItem.Click += new System.EventHandler(this.显示ToolStripMenuItem_Click);
        //
        // 退出ToolStripMenuItem
        //
        this.退出ToolStripMenuItem.Name = "退出ToolStripMenuItem";
        this.退出ToolStripMenuItem.Size = new System.Drawing.Size(94, 22);
        this.退出ToolStripMenuItem.Text = "退出";
        this.退出ToolStripMenuItem.Click += new System.EventHandler(this.退出ToolStripMenuItem_Click);
        //
        // timer2
        //
        this.timer2.Enabled = true;
        this.timer2.Interval = 1000;
        this.timer2.Tick += new System.EventHandler(this.timer2_Tick);
        //
        // Form1
        //
        this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
        this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
        this.ClientSize = new System.Drawing.Size(351, 403);
        this.Controls.Add(this.radioButton2);
        this.Controls.Add(this.radioButton1);
        this.Controls.Add(this.button2);
        this.Controls.Add(this.button1);
        this.Controls.Add(this.groupBox5);
        this.Controls.Add(this.groupBox4);
        this.Controls.Add(this.groupBox3);
        this.Controls.Add(this.groupBox2);
        this.Controls.Add(this.groupBox1);
        this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
        this.MaximizeBox = false;
        this.MinimizeBox = false;
        this.Name = "Form1";
        this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
        this.Text = "显示器控制";
        this.Load += new System.EventHandler(this.Form1_Load);
        this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.Form1_FormClosing);
        this.groupBox1.ResumeLayout(false);
        this.groupBox1.PerformLayout();
        ((System.ComponentModel.ISupportInitialize)(this.trackBar1)).EndInit();
        this.groupBox2.ResumeLayout(false);
        this.groupBox2.PerformLayout();
        this.groupBox3.ResumeLayout(false);
        this.groupBox4.ResumeLayout(false);
        this.groupBox4.PerformLayout();
        this.groupBox5.ResumeLayout(false);
        this.groupBox5.PerformLayout();
        this.contextMenuStrip1.ResumeLayout(false);
        this.ResumeLayout(false);
        this.PerformLayout();

    }

    #endregion

    private System.Windows.Forms.GroupBox groupBox1;
    private System.Windows.Forms.Label label2;
    private System.Windows.Forms.Label label1;
    private System.Windows.Forms.TrackBar trackBar1;
    private System.Windows.Forms.Label lblDisInfo;
    private System.Windows.Forms.GroupBox groupBox2;
    private System.Windows.Forms.GroupBox groupBox3;
    private System.Windows.Forms.ComboBox comboBox1;
    private System.Windows.Forms.GroupBox groupBox4;
    private System.Windows.Forms.ComboBox comboBox2;
    private System.Windows.Forms.CheckBox checkBox1;
    private System.Windows.Forms.GroupBox groupBox5;
    private System.Windows.Forms.Label label4;
    private System.Windows.Forms.Button button1;
    private System.Windows.Forms.Button button2;
    private System.Windows.Forms.Label lblInfo;
    private System.Windows.Forms.RadioButton radioButton1;
    private System.Windows.Forms.RadioButton radioButton2;
    private System.Windows.Forms.DateTimePicker dateTimePicker1;
    private System.Windows.Forms.Timer timer1;
    private System.Windows.Forms.NotifyIcon notifyIcon1;
    private System.Windows.Forms.ContextMenuStrip contextMenuStrip1;
    private System.Windows.Forms.ToolStripMenuItem 显示ToolStripMenuItem;
    private System.Windows.Forms.ToolStripMenuItem 退出ToolStripMenuItem;
    private System.Windows.Forms.Timer timer2;
}

到此这篇关于C#实现设置电脑显示器参数的文章就介绍到这了,更多相关C#设置电脑显示器参数内容请搜索我们以前的文章或继续浏览下面的相关文章希望大家以后多多支持我们!

(0)

相关推荐

  • C#通过热键控制显示器开关的方法

    本文实例讲述了C#通过热键控制显示器开关的方法.分享给大家供大家参考. 具体实现方法如下: 复制代码 代码如下: using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using Sys

  • C#运行程序时阻止关闭显示器和系统待机

    最近写了一个下载程序,发现有一个问题:挂机下载的时候,下载任务会因为系统休眠被终止掉. 最开始我的解决方法是关闭休眠,后来发现这种策略并不是很好:下载完成后,如果仍然继续保持开机状态浪费电. 因此,最好的方式是:在下载的时候阻止系统休眠.即不会因为休眠而终止下载任务,下载完成后自动转为休眠状态省电,都不用做下载完成后自动关机功能了. 查了一下相关文章,可以通过这个SetThreadExecutionState API实现阻止系统休眠.它在C#中的声明方式如下: [DllImport("kerne

  • C# Winform多屏幕多显示器编程技巧实例

    在窗口的中间有一个System.Windows.Forms.PictureBox控件(该控件区域的面积为所在窗口的1/4),当该控件的大部分区域落在其中一台显示器时,在另一台显示器将不显示该控件,(该PictureBox控件将移动到主显示器所在的窗口区域). 实现方法: using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Fo

  • C#实现将窗体固定在显示器的左上角且不能移动的方法

    本文实例讲述了C#实现将窗体固定在显示器的左上角且不能移动的方法.分享给大家供大家参考.具体实现方法如下: using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System

  • C#实现设置电脑显示器参数

    目录 实践过程 效果 代码 实践过程 效果 代码 public partial class Form1 : Form { public Form1() { InitializeComponent(); } string MaxValue;//显示器支持的最大刷新率 string MinValue;//显示器支持的最小刷新率 string NowValue;//当前刷新率 bool flag = true; public const uint WM_SYSCOMMAND = 0x0112; pub

  • php获取客户端电脑屏幕参数的方法

    本文实例讲述了php获取客户端电脑屏幕参数的方法.分享给大家供大家参考.具体分析如下: 首先需要说明的是php是服务器端的语言,是获取不到客户端的屏幕的宽度和高度的.但是有变通的方法就是通过客户端脚本语言javascript获取客户端的电脑屏幕的宽度和高度,然后通过ajax或者cookie的形式传递给php脚本语言,从而实现php获取客户端电脑屏幕宽度和高度的办法. 通过javascript获取客户端电脑的宽度,高度,分辨率的方法如下: 屏幕分辨率的高: window.screen.height

  • IntelliJ IDEA设置JVM运行参数的操作方法

    打开 IDEA 安装目录,看到有一个 bin 目录,其中有两个 vmoptions 文件,需针对不同的JDK进行配置: 32 位:idea.exe.vmoptions 64 位:idea64.exe.vmoptions -Xms512m -Xmx1024m -XX:MaxPermSize=512m -XX:ReservedCodeCacheSize=225m -XX:+UseConcMarkSweepGC -XX:SoftRefLRUPolicyMSPerMB=50 -ea -Dsun.io.u

  • laravel框架中路由设置,路由参数和路由命名实例分析

    本文实例讲述了laravel框架中路由设置,路由参数和路由命名.分享给大家供大家参考,具体如下: laravel中必须先配置路由,才能使用.不像tp中不配置也能使用,因为tp可以通过pathinfo进行自动解析. 一.简单的路由设置 我们一般在routes/web.php文件中配置网页端路由. //参数一,表示uri路径 //参数二,闭包函数,处理响应 Route::get('/test', function () { return '测试'; }); 二.路由方法,处理特定http请求方式 R

  • IDEA设置JVM运行参数的方法步骤

    前言 有时候我们需要在程序运行的时候对程序设置环境变量,恰巧我也遇到了这个问题,所以在此记录一下IDEA是如何设置环境变量的. 作用   -Dproperty=Value 该参数通常用于设置系统级全局变量值,如配置文件路径,保证该属性在程序中任何地方都可访问.当然,也可以通过在程序中使用System.setProperty进行设置. 注意: 1.如果-Dproperty=value的value中包含空格,可以将value使用引号引起来.例如:-Dmyname="hello world"

  • pycharm实现设置自动的参数注释标识

    目录 设置自动的参数注释标识 使用场景 设置步骤 pycharm技巧自动生成文件注释 设置自动的参数注释标识 如何使用pycharm自动添加引用注释描述功能 使用场景 多行注释,且需要对传入的参数以及返回值进行详尽的阐述时,如下图 设置步骤 pycharm技巧自动生成文件注释 1.打开pycharm 2.点击file——>settings 3.editor——>File and Code Templates——>Python Script——>编写注释——>OK 4.创建一个

  • idea设置JVM运行参数的几种方式

    目录 方式一 方式二 方式三 对JVM运行参数进行修改是JVM性能调优的重要手段,下面介绍在应用程序开发过程中JVM参数设置的几种方式. 方式一 java程序运行时指定 -Dproperty=value 该参数通常用于设置系统级全局变量值,如配置文件路径,保证该属性在程序中任何地方都可访问.当然,也可以通过在程序中使用System.setProperty进行设置. 注意: 1.如果-Dproperty=value的value中包含空格,可以将value使用引号引起来.例如:-Dmyname="h

  • Eclipse IDE中如何设置JVM启动参数

    目录 如何设置JVM启动参数 下面是一些设置的步骤 在Eclipse上手动设置jvm参数 典型设置 如何设置JVM启动参数 关于<深入理解Java虚拟机>里面测试OutOfMemoryError异常的部分,需要对虚拟机的启动参数进行设置 下面是一些设置的步骤 1. 右键选择项目,在弹出的菜单进行选择 2. 在弹出的Debug Configurations面板,左侧的type filter text下面选择Java Application,找到自己的项目,例如我的项目HeapOOM. 3. 在D

  • IntelliJ IDEA设置JVM运行参数的图文介绍

    目录 前言 配置方式及优先级 代码中配置 对某个Application设置 1 进入IDEA,Run–>Edit Configurations 选中要添加JVM参数的Application idea.exe.vmoption配置文件中更改 优先级 前言 之前看java虚拟机方面的知识,从理论上了解了较多的调优原理及参数,疑惑怎么才能在生产环境中设置这些虚拟机参数,今天特地学习并记录. 之前给大家介绍过几篇关于idea设置JVM运行参数的文章,喜欢的话可以点击阅读. IntelliJ IDEA设置

  • java -jar设置添加启动参数实现方法

    目录 java -jar设置添加启动参数方法 -DpropName=propValue 参数直接跟在命令后面 springboot的方式,--key=value方式 java -jar命令详解 第1种 第2种 第3种 第4种 第5种 总结 java -jar设置添加启动参数方法 java -jar 参数前后位置说明 springboot项目启动的时候可以直接使用java -jar xxx.jar这样.下面说说参数的一些讲究 -DpropName=propValue -DpropName=prop

随机推荐