根据桌面大小设置窗体大小

实现效果:

  

 知识运用:

  获取桌面大小时,主要用到了Screen类: 表是单个系统上的一个或多个显示设备

  其PrimaryScreen属性用来获取主显示 返回一个Screen对象

  而调用Screen对象的WorkingArea属性可以获取显示器的工作区 

实现代码:

        private void Form1_Load(object sender, EventArgs e)
        {
            int Width=Screen.PrimaryScreen.WorkingArea.Width;       //获取桌面宽度
            int Height = Screen.PrimaryScreen.WorkingArea.Height;      //获取桌面高度
            this.Width = Convert.ToInt32(Width*0.5);            //设置窗体宽度
            this.Height = Convert.ToInt32(Height*0.5);             //设置窗体高度
        }

猜你喜欢

转载自www.cnblogs.com/feiyucha/p/10094007.html