C#自适应窗体大小

版权声明:转载请注明出处 https://blog.csdn.net/s20160203/article/details/83029186

System.Drawing.Rectangle rect = Screen.GetWorkingArea(this); //获取工作电脑的Screen的矩形

            int width = rect.Width;
            int height = rect.Height;
            this.Size = new Size(width, height);
            this.Location = new Point((width - this.Width) / 2, (height - this.Height) / 2);  //用于固定启动程序是窗口的左上角的位置,

这样获取到了屏幕的尺寸,之后所设计控件的布局时要根据其比例大小去设计(代码写到加载函数中)。

猜你喜欢

转载自blog.csdn.net/s20160203/article/details/83029186