zoukankan      html  css  js  c++  java
  • 限制鼠标的移动范围

    利用api 函数 ClipCursor和GetWindowRect可以实现限定鼠标移动范围的功能。
     
    [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();

                _ScreenRect.top = 0;
                _ScreenRect.left = 0;
                _ScreenRect.bottom = int.MaxValue; ;
                _ScreenRect.right = int.MaxValue;
                ClipCursor(ref   _ScreenRect);
            }
            private void bntKong_Click(object sender, EventArgs e)
            {
                this.Lock(this);
            }

            private void bntMove_Click(object sender, EventArgs e)
            {
                this.UnLock();
            }

    微软BI技术交流群:316744959 武汉NET技术群:961108969 NET技术群:21386099 本人具有丰富的系统开发经验,承接系统开发,小程序,NET系统开发,BI开发,有需求联系微信手机:15010195887
  • 相关阅读:
    Linux 目录结构
    date命令--修改linux系统时间
    uniq linux下去除重复行命令
    Linux查看程序端口占用情况
    openfire连接登陆优化方案
    hdu 4848 搜索+剪枝 2014西安邀请赛
    经常使用ARM汇编指令
    一维DFT
    C++ lambda 表达式传递的变量默认不可变
    wm命令用法及LCD显示图标大小不正常时解决的方法
  • 原文地址:https://www.cnblogs.com/Impulse/p/1166873.html
Copyright © 2011-2022 走看看