Read out center of screen

Hi there...

I already did this, but there must be a more convenient way to do this:
How can I get the position of a form, which just startet with the StartPosition set to ScreenCenter
By just getting it's Location, it returns (0,0), but (0,0) is the left upper corner, actually.
I need this, becaue the form gets resized later on. I want to give the user the  opportunity to restart the program.
By restarting the form should just return to its original size and POSITION (center).


Thanks,
Finch.


Answer this question

Read out center of screen

  • A kid

    I assume You're reading forms location before the form is shown (in its constructor or initialize()). You should do it a bit later, after the form gets shown. Do it for example in the Form.Load event handler and you'll get right values.

  • Bart1

    Instead of relying on the screen coordinates (which can be wrong when the resolution changes), you can call the forms CenterToScreen method.

  • Read out center of screen