C# winform窗口居中

//不知道啥问题FormStartPosition.CenterScreen不好使,根据屏幕来设定了

            int height = System.Windows.Forms.SystemInformation.WorkingArea.Height;
            int width = System.Windows.Forms.SystemInformation.WorkingArea.Width;
            int formheight = this.Size.Height;
            int formwidth = this.Size.Width;
            int newformx = width / 2 - formwidth / 2;
            int newformy = height / 2 - formheight / 2;
            this.SetDesktopLocation(newformx, newformy);

猜你喜欢

转载自blog.csdn.net/mehnr/article/details/80914906