C# 将窗口位置设置在中间

C# 将窗口位置设置在中间,c#,.net,vb.net,visual-studio-2012,C#,.net,Vb.net,Visual Studio 2012,在VS2012中,我已将开始位置设置为屏幕右上角附近的手动位置。 我试图稍后通过单击将此窗口设置在中心,但无论我做什么,它都不会在中心。。我该怎么做呢?使用方法使用方法只需将此代码添加到按钮单击事件中 this.Location = new Point((SystemInformation.PrimaryMonitorSize.Width - this.Width) / 2, (SystemInformation.PrimaryMonitorSize.Height - this.Height)

在VS2012中,我已将开始位置设置为屏幕右上角附近的手动位置。
我试图稍后通过单击将此窗口设置在中心,但无论我做什么,它都不会在中心。。我该怎么做呢?

使用方法

使用方法

只需将此代码添加到按钮单击事件中

this.Location = new Point((SystemInformation.PrimaryMonitorSize.Width - this.Width) / 2, (SystemInformation.PrimaryMonitorSize.Height - this.Height) / 2);

只需将此代码添加到按钮单击事件

this.Location = new Point((SystemInformation.PrimaryMonitorSize.Width - this.Width) / 2, (SystemInformation.PrimaryMonitorSize.Height - this.Height) / 2);

您已将位置设置为手动,对于按钮单击,是否要将其居中?@AccessDenied开始手动时是,单击时我要将其居中..您已将位置设置为手动,对于按钮单击,是否要将其居中?@AccessDenied开始手动时是,单击时我要将其居中。。