C# winform解决解决窗体第一次设置为最大化后,点击最大化按钮窗体无法居中问题

public frmMain()
{
InitializeComponent();

//解决窗体第一次设置为最大化后,点击最大化按钮窗体无法居中问题
int x = Convert.ToInt32((Screen.PrimaryScreen.WorkingArea.Width - this.Width) * 0.5);
int y = Convert.ToInt32((Screen.PrimaryScreen.WorkingArea.Height - this.Height) * 0.5);
this.SetBounds(x, y, this.Width, this.Height, BoundsSpecified.All);
}

你可能感兴趣的:(WinForm)