Loren Pechtel
Loren Pechtel

Reputation: 9093

How to ensure my form is visible in C#?

I'm looking for a way to check to see that a window I am creating is visible and entirely on one monitor. I have seen too many programs do nasty things when they try to restore their position and the place no longer exists and I don't want my program to be vulnerable to this.

How do I find the information on the actual layout of the monitors?

Upvotes: 3

Views: 865

Answers (2)

Brad
Brad

Reputation: 51

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

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

Upvotes: 3

GvS
GvS

Reputation: 52538

The Screen class contains a lot of functionality for this.

You should check for yourself if a form is outside the Bounds of the Screen, but this is pretty straightforward:

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

Upvotes: 3

Related Questions