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
  • 相关阅读:
    归并排序
    [转]html5 Canvas画图教程(1)—画图的基本常识
    [转]浏览器工作原理
    [转]Web开发者和设计师必须要知道的 iOS 8 十个变化
    mobile web开发(1) html页面头部基本设置
    差点难产的HTML5
    感觉离开了好久
    Java----区别
    MySQL---sql语句优化
    MySQL---数据库优化
  • 原文地址:https://www.cnblogs.com/Impulse/p/1166873.html
Copyright © 2011-2022 走看看