How to ensure that my form is visible in C #?

I am looking for a way to verify that the window that I create is visible and completely on the same monitor. I saw that too many programs do unpleasant things when they try to regain their position, and the place no longer exists, and I do not want my program to be vulnerable to this.

How to find information about the actual location of monitors?

+3
source share
2 answers

The Screen class contains many functions for this.

You should check yourself if the form is outside the borders of the screen, but it is quite simple:

if (!Screen.GetWorkingArea(myWindow).Bounds.Contains(myWindow.Bounds)) {
   // Adjust location
}
+3
source

Just a small syntax correction, or possibly an update in Visual Studio 2012:

if (!Screen.GetWorkingArea(myWindow).Contains(myWindow.Bounds))
{
    //Adjust location
}
+3

Source: https://habr.com/ru/post/1757745/


All Articles