开发者

How can I programmatically determine the size of my desktop?

开发者 https://www.devze.com 2023-01-04 17:01 出处:网络
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

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 bo开发者_开发问答unds?


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.


Have you looked at the Screen class?

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

0

精彩评论

暂无评论...
验证码 换一张
取 消