开发者

How to ensure my form is visible in C#?

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

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 开发者_Python百科my program to be vulnerable to this.

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


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
}


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

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

精彩评论

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