请问有什么方法可以让窗口靠边隐藏  类似于QQ等窗口的特效

解决方案 »

  1.   

    http://blog.csdn.net/sunchaohuang/archive/2009/02/18/3903682.aspx
      

  2.   

    这个原理比较简单。使用一个timer控件,定时获取当前鼠标的位置,如果鼠标的位置不在屏幕内,则将窗体进行隐藏。代码如下: #region 窗体隐藏
            class Win32API
            {
                [DllImport("User32.dll")]
                public static extern bool PtInRect(ref Rectangle r, Point p);
            }
            private void timer1_Tick(object sender, EventArgs e)
            {
                System.Drawing.Point  pp=new  Point(Cursor.Position.X,Cursor.Position.Y);//获取鼠标在屏幕的坐标点
                Rectangle Rects = new Rectangle(this.Left, this.Top, this.Left + this.Width, this.Top + this.Height);//存储当前窗体在屏幕的所在区域
                if ((this.Top < 0) && Win32API.PtInRect(ref Rects, pp))//当鼠标在当前窗体内,并且窗体的Top属性小于0
                    this.Top = 0;//设置窗体的Top属性为0
                else
                    //当窗体的上边框与屏幕的顶端的距离小于5时
                    if (this.Top > -5 && this.Top < 5 && !(Win32API.PtInRect(ref Rects, pp)))
                        this.Top = 5 - this.Height;//将QQ窗体隐藏到屏幕的顶端        }
            #endregion
      

  3.   

    public static void SideHideOrShow(Form DockableForm, ref int DockFormHeight, Timer _dockTimer)
        {
            if (DockableForm.WindowState != FormWindowState.Minimized)
            {
                _dockTimer.Interval = 100;
                if (Cursor.Position.X > DockableForm.Left - 1 && Cursor.Position.X < DockableForm.Right && Cursor.Position.Y > DockableForm.Top - 1 && Cursor.Position.Y < DockableForm.Bottom)
                {
                    if (DockableForm.Top <= 0 && DockableForm.Left > 5 && DockableForm.Left < Screen.PrimaryScreen.WorkingArea.Width - DockableForm.Width)
                    {
                        DockableForm.Top = 0;
                    }
                    else if (DockableForm.Left <= 0)
                    {
                        DockableForm.Left = 0;
                    }
                    else if (DockableForm.Left + DockableForm.Width >= Screen.PrimaryScreen.WorkingArea.Width)
                    {
                        DockableForm.Left = Screen.PrimaryScreen.WorkingArea.Width - DockableForm.Width;
                    }
                    else
                    {
                        if (DockFormHeight > 0)
                        {
                            DockableForm.Height = DockFormHeight;
                            DockFormHeight = 0;
                        }
                    }
                }
                else
                {
                    if (DockFormHeight < 1)
                    {
                        DockFormHeight = DockableForm.Height;
                    }
                    if (DockableForm.Top <= 4 && DockableForm.Left > 5 && DockableForm.Left < Screen.PrimaryScreen.WorkingArea.Width - DockableForm.Width)
                    {
                        DockableForm.Top = 3 - DockableForm.Height;
                        if (DockableForm.Left <= 4)
                        {
                            DockableForm.Left = -5;
                        }
                        else if (DockableForm.Left + DockableForm.Width >= Screen.PrimaryScreen.WorkingArea.Width - 4)
                        {
                            DockableForm.Left = Screen.PrimaryScreen.WorkingArea.Width - DockableForm.Width + 5;
                        }
                    }
                    else if (DockableForm.Left <= 4)
                    {
                        DockableForm.Left = 3 - DockableForm.Width;
                    }
                    else if (DockableForm.Left + DockableForm.Width >= Screen.PrimaryScreen.WorkingArea.Width - 4)
                    {
                        DockableForm.Left = Screen.PrimaryScreen.WorkingArea.Width - 3;
                    }
                    _dockTimer.Interval = 100;
                }
            }
        }