简体   繁体   English

如何确定是否按下了鼠标左键?

[英]How to determine whether the left mouse button is pressed?

In a winform, the form will follow the mouse when the mouse is down, but sometimes when the machine particularly is slow, the form is following the mouse even the mouse is out, so I used win32 dll to judge the state of the mouse 在winform中,当鼠标按下时,该窗体将跟随鼠标,但是有时在机器特别慢的情况下,即使鼠标不在,该窗体也会跟随鼠标,因此我使用win32 dll来判断鼠标的状态

 [DllImport("user32.dll")]
    static extern short GetAsyncKeyState(int nVirtKey);
    public static bool GetCurrentLeftMouseIsDowning()
    {
        if (GetAsyncKeyState(0x01) == 0)
            return false;
        else
            return true;
    }

But the memory will increase when the form has been dragging, and what other way to determine the state of the mouse?Or how to control the memory when the form is dragged?? 但是当拖动表格时,内存会增加,用其他方法确定鼠标状态?或者拖动表格时如何控制内存?

Considering you are using winform, you can use form1_mousedown event for this 考虑到您使用的是winform,可以为此使用form1_mousedown事件

refer this 参考这个

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM