XK8ER
XK8ER

Reputation: 780

Set window position in the center

I have set the start position to manual somewhere around the top right of the screen in VS2012. I am trying to later on set this window in the center with one click but no matter what I do its never in the center.. how can I do that?

Upvotes: 2

Views: 1325

Answers (2)

Kurubaran
Kurubaran

Reputation: 8902

Just add this code to your button click event,

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

Upvotes: 3

Imtiaz Zaman Nishith
Imtiaz Zaman Nishith

Reputation: 490

Use Form.CenterToScreen method

Upvotes: 1

Related Questions