下面是一个窗体控件屏幕边缘自动隐藏的方法 麻烦就大哥给个注释 要求是每行一个!注释 谢谢 每个30分钟进来一次 注释加好 立刻给分!注释越详细越好 private void timer1_Tick(object sender, EventArgs e)
        {
            if (WindowState != FormWindowState.Minimized)
            {
                int ScreenWidth = Screen.PrimaryScreen.WorkingArea.Width;  //屏幕宽度 
                int ScreenRight = Screen.PrimaryScreen.WorkingArea.Right; //屏幕高度 
                int MouseX = Control.MousePosition.X; //鼠标X位置 
                int MouseY = Control.MousePosition.Y;//鼠标垂直位置 
                if (this.Left < 0 && this.Top < 0)
                {
                    this.Left = 0;
                    this.Top = 1;
                }
                if (this.Left >= ScreenWidth - this.Right && this.Top < 0) //如果自己的左边是否在屏幕的边缘 
                {
                    this.Left = ScreenWidth;
                    this.Top = 0;
                }
                if (this.Top < 0 && MouseX > this.Left && MouseX < this.Left + this.Width && MouseY < 3)
                {
                    this.Top = 0;
                }
                if (this.Top <= 0 && this.Left > 0 && this.Left < ScreenWidth - this.Width)
                {
                    if (MouseX < this.Left || MouseX > this.Left + this.Width || MouseY > this.Top + this.Right)
                    {
                        this.Top = 3 - this.Right;
                    }
                }
                if (this.Left < 0 && MouseY > this.Top && MouseY < this.Top + this.Width && MouseX < 3)
                {
                    this.Left = 0;
                }
                if (this.Left <= 0 && this.Top > 0 && this.Top < ScreenRight - this.Right)
                {
                    if (MouseY < this.Top || MouseY > this.Top + this.Right || MouseX > this.Width)
                    {
                        this.Left = 3 - this.Width;
                    }
                }
                if (this.Left >= ScreenWidth - this.Width && this.Top > 0 && this.Top < ScreenRight - this.Width)
                {
                    if (MouseY < this.Top || MouseY > this.Top + this.Right || MouseX < ScreenWidth - this.Width)
                    {
                        this.Left = ScreenWidth - 3;
                    }
                }                if (this.Left > ScreenWidth - 5) //判断自己的左边是否隐藏了 
                {
                    if (MouseX > ScreenWidth - 5)  //如果隐藏了  判断鼠标是不在屏幕的边缘 
                    {
                        this.Left = ScreenWidth - this.Width;
                    }
                }
            } 
        } 

解决方案 »

  1.   

    注释了一部分
    this.Left  窗体左边沿
    this.Top   窗体上边沿
    就这么几种情况,楼主认真分析下并不是很难的.
     private void timer1_Tick(object sender, EventArgs e)
            {
                if (WindowState != FormWindowState.Minimized)
                {
                    int ScreenWidth = Screen.PrimaryScreen.WorkingArea.Width;  //屏幕宽度             
                    int ScreenRight = Screen.PrimaryScreen.WorkingArea.Right; //屏幕高度
                    int MouseX = Control.MousePosition.X; //鼠标X位置
                    int MouseY = Control.MousePosition.Y;//鼠标垂直位置
                    if (this.Left < 0 && this.Top < 0)//窗体在左上角
                    {
                        this.Left = 0;//自己的左边恰好在屏幕的边缘
                        this.Top = 1;//自己的上边缘在屏幕上方1像素的位置  即屏幕左上角
                    }
                    if (this.Left >= ScreenWidth - this.Right && this.Top < 0) //如果自己的右边是否在屏幕的边缘
                    {
                        //隐藏在屏幕的右上角
                        this.Left = ScreenWidth;
                        this.Top = 0;
                    }
                    if (this.Top < 0 && MouseX > this.Left && MouseX < this.Left + this.Width && MouseY < 3)
                    {
                        this.Top = 0;
                    }
                    if (this.Top <= 0 && this.Left > 0 && this.Left < ScreenWidth - this.Width)
                    {
                        if (MouseX < this.Left || MouseX > this.Left + this.Width || MouseY > this.Top + this.Right)
                        {
                            this.Top = 3 - this.Right;
                        }
                    }
                    if (this.Left < 0 && MouseY > this.Top && MouseY < this.Top + this.Width && MouseX < 3)
                    {
                        this.Left = 0;
                    }
                    if (this.Left <= 0 && this.Top > 0 && this.Top < ScreenRight - this.Right)
                    {
                        if (MouseY < this.Top || MouseY > this.Top + this.Right || MouseX > this.Width)
                        {
                            this.Left = 3 - this.Width;
                        }
                    }
                    if (this.Left >= ScreenWidth - this.Width && this.Top > 0 && this.Top < ScreenRight - this.Width)
                    {
                        if (MouseY < this.Top || MouseY > this.Top + this.Right || MouseX < ScreenWidth - this.Width)
                        {
                            this.Left = ScreenWidth - 3;
                        }
                    }                if (this.Left > ScreenWidth - 5) //判断自己的左边是否隐藏了
                    {
                        if (MouseX > ScreenWidth - 5)  //如果隐藏了  判断鼠标是不在屏幕的边缘
                        {
                            this.Left = ScreenWidth - this.Width;
                        }
                    }
                }        }
      

  2.   

    this.Left;   //窗体的左上角的x坐标
    this.Top;   //窗体的左上角的y坐标
     
    if (this.Left < 0 && this.Top < 0) //获取当前窗体的左位置
                    { 
                        this.Left = 0; 
                        this.Top = 1; 
                    } 
    if (this.Left >= ScreenWidth - this.Width && this.Top > 0 && this.Top < ScreenRight - this.Width) //当前左位置是否大于屏幕宽度与窗体宽带之差和左上角的y坐标是否大于0或小于屏幕 高度和窗体高度之差               { 
                        if (MouseY < this.Top || MouseY > this.Top + this.Right || MouseX < ScreenWidth - this.Width) 
                        { 
                            this.Left = ScreenWidth - 3; 
                        } 
                    }