首页 > 移动平台 > 详细

WinForm不让窗体移动到屏幕外

时间:2016-01-07 10:16:10      阅读:436      评论:0      收藏:0      [点我收藏+]

不让Form移动到屏幕外,先给窗体添加Move事件,然后判断并重新设置位置。

代码:

private void FormMain_Move(object sender, EventArgs e)
        {
            Rectangle r = Screen.GetWorkingArea(this);
            if(this.Top <=0)
            {
                this.Top = r.Top;
            }
            if (this.Left <=0)
            {
                this.Left = 0;
            }
            if (this.Right > r.Right)
            {
                this.Left = r.Right - this.Width;
            }
            if (this.Bottom > r.Bottom)
            {
                this.Top = r.Bottom - this.Height;
            }
        }

 

WinForm不让窗体移动到屏幕外

原文:http://www.cnblogs.com/lantianyuyang/p/5108690.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!