从我类库里抽出来的锁定在一个窗体里你改改就可以用了吧
public static void Lock( System.Windows.Forms.Form ObjectForm )// have to lock the objectform size !!!
{
Win32API.RECT _FormRect = new Win32API.RECT ();
Win32API.GetWindowRect( ObjectForm.Handle.ToInt32() , ref _FormRect );
Win32API.ClipCursor( ref _FormRect );
}

public static void UnLock()
{
Win32API.RECT _ScreenRect = new Win32API.RECT ();
_ScreenRect.Top = 0;
_ScreenRect.Left = 0;
_ScreenRect.Bottom = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Bottom;
_ScreenRect.Right = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Right;

Win32API.ClipCursor( ref _ScreenRect );
}