int titleHeight = System.Windows.Forms.SystemInformation.CaptionHeight;
Point myFormPoint = this.PointToScreen(new Point(0,0-titleHeight));
Rectangle rect = new Rectangle(myFormPoint, new Size(this.ClientRectangle.Width,this.ClientRectangle.Height + titleHeight));
System.Windows.Forms.Cursor.Clip = rect;
[System.Runtime.InteropServices.DllImport("user32", EntryPoint = "ClipCursor")]
public extern static int ClipCursor(ref RECT lpRect);
[System.Runtime.InteropServices.DllImport("user32.dll", EntryPoint = "GetWindowRect")]
public extern static int GetWindowRect(int hwnd, ref RECT lpRect);
public struct RECT//声明参数的值
{
public int left;
public int top;
public int right;
public int bottom;
}
public void Lock(System.Windows.Forms.Form ObjectForm)
{
RECT _FormRect = new RECT();
GetWindowRect(ObjectForm.Handle.ToInt32(), ref _FormRect);
ClipCursor(ref _FormRect);
}
public void UnLock()
{
RECT _ScreenRect = new RECT();