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
  • 相关阅读:
    CSS基础学习记录——CSS选择器及其特殊性计算
    CSS基础学习记录——CSS中哪些属性可以继承?
    行内框和行框的概念,line-height和vertical-align的关系理解
    【转】DOM中NodeList、HTMLCollection、NamedNodeMap三个动态集合的理解
    property参数讲解
    CocoaPods安装方法
    ios UITextField 以及键盘显示总结
    Xcode11 在Xib中进行UIScrollView布局
    锁问题总结-同一个线程两次获取同一把锁
    【转载】ARM MMU详解
  • 原文地址:https://www.cnblogs.com/Impulse/p/1166873.html
Copyright © 2011-2022 走看看