using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.Runtime.InteropServices;namespace MyQQ
{
    class API
    {
        [DllImport("user32.dll")]
        public static extern bool PtInRect(ref Rectangle r, Point p);
    }
}
////////////////////////////////////// API 的类;
////////////////////////////////// 下面是一个time 的TICK的代码 : 
            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);
            //鼠标在当前窗体中,并且窗体顶部属性小于0
            if ((this.Top < 0) && API.PtInRect(ref Rects, pp))
                this.Top = 0;
            else
            {
                
                if (this.Top > -5 && this.Top < 5 && !(API.PtInRect(ref Rects, pp)))
                    this.Top = 5 - this.Height;
            } if ((this.Left< 0) && API.PtInRect(ref Rects, pp))
                this.Left = 0;
            else
            {
                
                if (this.Left > -5 && this.Left < 5 && !(API.PtInRect(ref Rects, pp)))
                    this.Left = 5 - this.Width;
            }
            if ((this.Right < 0) && API.PtInRect(ref Rects, pp))
                this.Right = 0;
            else
            {
                
                if (this.Right> -5 && this.Top < 5 && !(API.PtInRect(ref Rects, pp)))
                    this.Right = 5 - this.Width;
            }/////////////////////  实现效果与QQ挪至桌面边缘,让QQ自动隐藏的效果一样。 谁能讲解下吗?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);
            //鼠标在当前窗体中,并且窗体顶部属性小于0
            if ((this.Top < 0) && API.PtInRect(ref Rects, pp))
                this.Top = 0;
            else
            {
                
                if (this.Top > -5 && this.Top < 5 && !(API.PtInRect(ref Rects, pp)))
                    this.Top = 5 - this.Height;
            }  谢谢  了

解决方案 »

  1.   

    ?System.Drawing.Point pp = new Point(Cursor.Position.X, Cursor.Position.Y); //获取鼠标的x,y坐标
                //存储窗体的区域 
                Rectangle Rects = new Rectangle(this.Left, this.Top, this.Left + this.Width, this.Top + this.Height); //得到当前窗体的矩形区域
                //鼠标在当前窗体中,并且窗体顶部属性小于0 
                if ((this.Top < 0) && API.PtInRect(ref Rects, pp)) //这个函数怎样实现的不清楚。。但看注释应该是判断鼠标是否在当前窗体中
                    this.Top = 0; //当窗体的top小于0时让其回到0
                else 
                { 
                    
                    if (this.Top > -5 && this.Top < 5 && !(API.PtInRect(ref Rects, pp))) 
                        this.Top = 5 - this.Height; 
                } 谢谢  了
      

  2.   


    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); //存储当前窗体在屏幕的所在区域
                //鼠标在当前窗体中,并且窗体顶部属性小于0 
                if ((this.Top < 0) && API.PtInRect(ref Rects, pp)) //当鼠标在当前窗体内,并且窗体的Top属性小于0                this.Top = 0; // //设置窗体的Top属性为0,就是将窗口上边沿紧靠顶部
                else 
                { 
                    
                    if (this.Top > -5 && this.Top < 5 && !(API.PtInRect(ref Rects, pp))) //当窗体的上边框与屏幕的顶端的距离小于5时
                        this.Top = 5 - this.Height; //将窗体隐藏到屏幕的顶端(类似于QQ窗体拖到顶的时候,会自动隐藏)            } 
      

  3.   

    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) && API.PtInRect(ref Rects, pp)) //判断点是否在矩形中 
     this.Top = 0; 
    else 

    if (this.Top > -5 && this.Top < 5 && !(API.PtInRect(ref Rects, pp))) 
          this.Top = 5 - this.Height;