VS2017 C# winForm 还原窗口时居中显示

在窗口的resize事件中写代码

        private void Form_Order_Content_Resize(object sender, EventArgs e)
        {
            //还原窗口时居中显示
            int screenTop = (System.Windows.Forms.Screen.GetWorkingArea(this).Width-this.Width)/2;
            int screenLeft = (System.Windows.Forms.Screen.GetWorkingArea(this).Height-this.Height)/2;
            if (this.WindowState == FormWindowState.Normal)
            {
                this.Location = new Point(screenTop, screenLeft);
            }
        }

 

posted @ 2018-04-13 15:46  履霜.1989  阅读(1263)  评论(0编辑  收藏  举报