use api CilpCursor(ref Rectangle);

解决方案 »

  1.   

    分别要写MouseEnter 
    MouseMove 
    MouseHover/MouseDown/MouseWheel 
    MouseUp 
    MouseLeave 这几个事件我给个MouseMove 的其它差不多
     protected override void OnMouseMove(MouseEventArgs mea)
    {if((this.ClientRectangle.lift<mea.x<this.ClientRectangle.right)&&
    this.ClientRectangle.top<mea.y<this.ClientRectangle.bottom)
    //do somethingelse
    return;
      

  2.   

    [StructLayout(LayoutKind.Explicit)] 
    public struct Rect 

    [FieldOffset(0)] public int left; 
    [FieldOffset(4)] public int top; 
    [FieldOffset(8)] public int right; 
    [FieldOffset(12)] public int bottom; 

    [DllImportAttribute ("user32.dll")] 
    public static extern int ClipCursor(ref Rect r);private void button3_Click(object sender, System.EventArgs e)
    {
    Rect a;
    Rectangle r=this.ClientRectangle;
    r.Offset(this.Location);
    a.top=r.Top ;
    a.right =r.Right ;
    a.bottom =r.Bottom;
    a.left =r.Left;
    ClipCursor(ref a);
    }
    }
      

  3.   

    可以简单点的,不要Rect
    [DllImportAttribute ("user32.dll")] 
    public static extern int ClipCursor(ref  Rectangle r);private void button3_Click(object sender, System.EventArgs e)
    {
    Rectangle r=this.ClientRectangle;
    r.Offset(this.Location);
    ClipCursor(ref a);
    }
    }
      

  4.   

    解决了,可以设置
    System.Windows.Forms.Cursor.Clip