确定一种形式是完全关闭屏幕 [英] Determining if a form is completely off screen

查看:112
本文介绍了确定一种形式是完全关闭屏幕的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发记住用户的喜好,以表格的最后位于屏幕里的应用程序。在某些情况下,用户将有它的次级屏幕上,然后再触发应用时没有所述第二屏幕(有时具有的形式出现断屏幕)。其他时候,用户会改变产生类似的效果予以解决。

I am developing an application that remembers the user's preferences as to where the form was last located on the screen. In some instances the user will have it on a secondary screen, and then fire the app up later without the second screen (sometimes having the form appear off screen). Other times the user will change their resolution resulting in a similar effect.

我希望做的Form_Shown事件处理此检查。基本上我想要确定表单是否完全关闭屏幕,所以我可以重新定位它。

I was hoping to do this checking in the Form_Shown event handler. Basically I want to determine whether the form is completely off screen so I can re-position it.

任何意见?

推荐答案

用此功能检查,如果表是完全在屏幕上:

check with this function if Form is fully on screen:

public bool IsOnScreen(Form form)
    	{
    		Screen[] screens = Screen.AllScreens;
    		foreach (Screen screen in screens)
    		{
    			Rectangle formRectangle = new Rectangle(form.Left,form.Top,form.Width, form.Height);

    			if (screen.WorkingArea.Contains(formRectangle))
    			{
    				return true;
    			}
    		}

    		return false;
    	}



检查仅左上点,如果它在屏幕上:

checking only TopLeft point if it's on screen:

public bool IsOnScreen(Form form)
    	{
    		Screen[] screens = Screen.AllScreens;
    		foreach (Screen screen in screens)
    		{
    			Point formTopLeft = new Point(form.Left, form.Top);

    			if (screen.WorkingArea.Contains(formTopLeft))
    			{
    				return true;
    			}
    		}

    		return false;
    	}

这篇关于确定一种形式是完全关闭屏幕的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆