RT:
类似于 QQ的 吸附功能 
就是把窗体 拖到右上角 快到的时候 自动吸附到 右上角 ,
鼠标在拖动窗体的时候又改回来··咋搞·····

解决方案 »

  1.   

    做一个判断
    if (this.Left < xxx) this.Left = 0;
      

  2.   

    为你的窗体设置属性,例如public Point 吸附之前窗体的最后坐标;然后再你的执行“吸附”功能的代码的第一行采集窗体左上角坐标和设置这个属性,“改回来”这个部分使用它。“吸附”,就是在触发拖动事件(鼠标移动事件,同时当前鼠标一直按下没有抬起来)并且没有设置这个属性(这个属性为null)时检测一下左边、右边、下边、上边。而“改回来”,就是这个事件中当这个属性不为null时的状态。
      

  3.   

    放一个timer1控件,interval设置成1秒//实现接近屏幕窗体边源吸附
            private void timer1_Tick(object sender, EventArgs e)
            {
                
                if (this.WindowState != System.Windows.Forms.FormWindowState.Minimized)
                {
                    if (Cursor.Position.X > this.Left && Cursor.Position.X < this.Right && Cursor.Position.Y > this.Top && Cursor.Position.Y < this.Bottom)
                    {
                        if (this.Top < 0)
                        {
                            this.Top = -5;
                            this.Show();
                        }
                        else if (this.Left < 0)
                        {
                            this.Left = -5;
                            this.Show();
                        }
                        else if (this.Left + this.Width >= Screen.PrimaryScreen.WorkingArea.Width)
                        {
                            this.Left = Screen.PrimaryScreen.WorkingArea.Width - this.Width + 5;
                            this.Show();
                        }
                    }
                    else
                    {
                        if (this.Top <= 4)
                        {
                            this.Top = 5 - this.Height;
                            if (this.Left <= 4)
                            {
                                this.Left = -5;
                            }
                            else if (this.Left + this.Width >= Screen.PrimaryScreen.WorkingArea.Width - 4)
                            {
                                this.Left = Screen.PrimaryScreen.WorkingArea.Width - this.Width + 5;
                            }
                        }
                        else if (this.Left <= 4)
                        {
                            this.Left = 5 - this.Width;
                        }
                        else if (this.Left + this.Width >= Screen.PrimaryScreen.WorkingArea.Width - 4)
                        {
                            this.Left = Screen.PrimaryScreen.WorkingArea.Width - 5;
                        }
                    }
                }        }