天天看点

winform窗体在当前显示窗口中居中

窗体在当前显示窗口中居中,两个方法:

①设置StartPosition

②Winform的Paint事件

private void form1_Paint(object sender, PaintEventArgs e)
        {
            int gLeft = this.Width /  - form1.Width / ;
            int gTop = this.Height /  - form1.Height / ;
            form1.Location = new Point(gLeft, gTop);
        }