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
  • 相关阅读:
    87 求先序排列
    iOS App用WKWebView加载h5, h5多页面手势返回,h5返回App
    H5判断是手机端浏览器or原生App Webview
    vue-router笔记
    我的博客园页面定制 CSS 代码
    用swiper实现不规则分页滚动 & 给分页器加颜色
    Angular1.6.9 选择本地文件上传后台
    Vue移动端上拉加载更多实现请求分页数据
    导航折叠菜单
    类似于Flipboard页面翻折效果
  • 原文地址:https://www.cnblogs.com/Impulse/p/1166873.html
Copyright © 2011-2022 走看看