rt...

解决方案 »

  1.   

    private void button1_Click(object sender, System.EventArgs e)
    {
    Cursor.Clip = new Rectangle(this.Location, this.Size);
    }
      

  2.   

    1.引用 
    using System.Runtime.InteropServices;
    2.
    /// <summary>
    /// 调用ClipCursor API用的结构
    /// </summary>
    struct Rect {
    public Rect(int ileft,int itop,int iright,int ibottom){
    this.left = ileft;
    this.top = itop;
    this.right = iright;
    this.bottom = ibottom;
    }
    public int left;
    public int top;
    public int right;
    public int bottom;
    } //调用API限定鼠标范围的函数
    [DllImport("user32.dll")]
    unsafe extern static private int ClipCursor(Rect * lrt);3.
    private void Form1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e) {
    Rectangle prt = this.RectangleToScreen(this.ClientRectangle);
    Rect rt = new Rect(prt.Left,prt.Top,prt.Right,prt.Bottom);
    unsafe {
    ClipCursor( &rt);
    }
    }注意,启用不安全模式,/unsafe 。
      

  3.   

    //解除鼠标范围限定
    unsafe {
    ClipCursor(null);
    }