How do I center a window onscreen in C#?

Sean picture Sean · Jan 5, 2011 · Viewed 221.3k times · Source

I need a way to center the current window. So for example, if a user pushes a button, I want the window to center itself onscreen. I know you can use the startposition property, but I cannot figure out a way to use that other than when the application first starts up. So how do I center the form on the screen?

Answer

dzendras picture dzendras · Jan 5, 2011

Use Form.CenterToScreen() method.