Answered by:
How can I tell if there is a missing monitor

Question
-
My desktop app saves the form size and position to preserve them between executions of the program. When a second monitor is connected, and a form is opened, it opens on the second monitor just fine. However, if that monitor is not connected, the form opens up where that monitor would be, but that makes it invisible on the single monitor. How can I figure out whether that virtual desktop area is actually being displayed or not, so I can reposition it to a visible area?
Mike
Thursday, May 18, 2017 1:15 AM
Answers
-
I think my answer is in this class:
System.Windows.Forms.Screen
I don't have all the details worked out, but it can tell me what screen it is on. Unfortunately that is not enough. If I have only my laptop screen, I can tell it is off the screen by checking the form properties against the width and height properties of the screen object. I get the screen object by using the form handle and the FromHandle method.
Unfortunately if there are multiple screens, the second screen width and height properties do not help because the form coordinates are out of range of those properties yet it is still visible. It will take more work, but I think I am looking in the right place now.
NOTE: I found what I needed in the WorkingArea property.
Mike
Thursday, May 18, 2017 10:27 PM
All replies
-
Hi MihaIvan,
Thank you for posting here.
The IsWindowOnCurrentVirtualDesktop method can Indicate whether the provided window is on the currently active virtual desktop. If the Virtual desktop is not active windows, it will not be displayed
Every window is considered to be part of a virtual desktop. When one virtual desktop is hidden, all of the windows associated with it are also hidden.
newly created windows should appear on the currently active virtual desktop. In addition, if an application can reuse currently active windows, it should only reuse windows if they are on the currently active virtual desktop. Otherwise, a new window should be created.
Best Regards,
Hart
Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.
Thursday, May 18, 2017 6:12 AM -
Thanks Hart. From the overview description of the class, that appears to be what I would need, but the problem is that it says the minimum requirement is Windows 10, and I need for it to work on a minimum of Windows 7. Any ideas that go back that far?
Mike
Thursday, May 18, 2017 1:24 PM -
Maybe MonitorFromWindow?
- Edited by RLWA32 Thursday, May 18, 2017 7:41 PM
Thursday, May 18, 2017 7:38 PM -
This is interesting question :) A milder form of it: user runs the app on a laptop with large external monitor, then hibernates and resumes in a train, with only the small screen. So... when you save size & position, save also the info about the monitor. If current monitor is not compatible with what you saved, do not restore.
-- pa
- Edited by Pavel A Thursday, May 18, 2017 8:42 PM
Thursday, May 18, 2017 8:42 PM -
I think my answer is in this class:
System.Windows.Forms.Screen
I don't have all the details worked out, but it can tell me what screen it is on. Unfortunately that is not enough. If I have only my laptop screen, I can tell it is off the screen by checking the form properties against the width and height properties of the screen object. I get the screen object by using the form handle and the FromHandle method.
Unfortunately if there are multiple screens, the second screen width and height properties do not help because the form coordinates are out of range of those properties yet it is still visible. It will take more work, but I think I am looking in the right place now.
NOTE: I found what I needed in the WorkingArea property.
Mike
Thursday, May 18, 2017 10:27 PM