views:

38

answers:

2

I'm trying to save / restore the window size, state and position of a System::Windows::Forms::Form and want to make sure that if the window was previously on another monitor and the app is started up when only a snogle monitor is available, that it puts itself somewhere on-screen.

So how can I determine the current desktop size and whether my application is out of bounds?

+2  A: 

Have you looked at the Screen class?

The Screen.WorkingArea property will give you the desktop size of your display.

CesarGon
+3  A: 

Actually, the best solution would be to use the native methods GetWindowPlacement and SetWindowPlacement in user32.dll. These automatically handle all the edge cases.

A sample WPF implementation using them can be found at http://jake.ginnivan.net/2010/04/remembering-wpf-windows-position-2/ From that you could do the same for WinForms.

Daniel Rose
+1/Accepted ..although by the time I read this, I'd already rolled my own :-)
Jon Cage