就象网吧管理软件,你没输密码,鼠标就离不开窗口一样?

解决方案 »

  1.   

    [StructLayout(LayoutKind.Sequential)]
        public struct RECT
        {
            public int left;
            public int top;
            public int right;
            public int bottom;
            public static RECT FromRectangle(Rectangle rc)
            {
                RECT RCTO = new RECT();
                RCTO.left = rc.Left;
                RCTO.top = rc.Top;
                RCTO.right = rc.Right;
                RCTO.bottom = rc.Bottom;
                return RCTO;
            }
        }[DllImport("user32.dll")]
    public static extern bool ClipCursor(ref RECT rect);[DllImport("user32.dll")]
    public static extern bool ClipCursor(IntPtr rect);// 取消鼠标限制
    ClipCursor(IntPtr.Zero);// 限制鼠标移动范围
    RECT rect = RECT.FromRectangle(this.RectangleToScree(this.ClientRectangle));
    ClipCursor(ref rect);
      

  2.   

    可以通过API判断当前鼠标所在窗体句柄是否和目标句柄相同,可以用时间来判断
      

  3.   

    或许可以通过MouseLeave事件实现吧