如何防止其他鼠标按钮中断MouseMove?
如果您将一个面板放置在一个新的 C# 项目中并捕获它的 MouseMove 事件,如下所示:
private void panel1_MouseMove(object sender, MouseEventArgs e)
{
if (e.Button != MouseButtons.Left)
return;
Console.WriteLine("e.X: {0}, e.Y: {1}", e.X, e.Y);
}
它会告诉您按住鼠标左键时鼠标的客户端坐标,即使光标移到面板之外也是如此。
但是,如果您在容器中按住鼠标左键,然后在按住鼠标左键的同时单击鼠标上的任何其他鼠标按钮,则在容器边界之外时,它不再调用 MouseMove。
有什么办法可以改变这个吗?感谢您的阅读。
If you place a panel in a new C# project and capture it's MouseMove event like this:
private void panel1_MouseMove(object sender, MouseEventArgs e)
{
if (e.Button != MouseButtons.Left)
return;
Console.WriteLine("e.X: {0}, e.Y: {1}", e.X, e.Y);
}
It tells you the client coordinates of the mouse while the left mouse button is held down, even if the cursor goes outside of the panel.
However, if you are holding down left mouse button in the container and then, while holding down left mouse button, click any other mouse button on your mouse, it no longer calls MouseMove while outside the bounds of the container.
Is there any way to change this? Thanks for reading.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
1:如果您试图让它仅在左按钮按下时工作,请尝试以下操作:
2:否则,如果您希望它在任意鼠标按钮按下时工作,请尝试以下操作:
1: If you are trying to get it to work only when the left button is down, try the following:
2: Otherwise, if you want it to work when any mouse button is down, try the following:
除了贾斯汀的解决方案之外,
我认为这是因为,如果在拖动过程中您走出面板,右键单击面板外面,则会强制面板失去焦点,因此控件不再成为一个活跃的一位。
如果您将鼠标拖动到面板内并在面板内单击鼠标右键,则会发生类似的情况。
我刚刚使用 Spy++ windows 资源管理器捕获并进行了测试,因此用 LButton 向下移动鼠标,并在某个时刻不释放它进行了右键单击。这是结果:
我用箭头签署了用右键单击的行,其中
查看下一行带箭头的内容。下一个窗口的句柄是0,所以没有任何窗口。所以这意味着,就像一个简单的命令:您丢失了鼠标捕获。
希望这有帮助。
In addition to Justin's solution will say that:
I think it's because, if during drag you go out of the panel right click out of the panel, forces panel to lose the focus, so control no more becomes an active one.
In case of when you're dragging mouse inside panel and click with right click inside panel, happens something like this.
I just captured with Spy++ windows explorer and did a test, so moved the mouse with LButton down and at some point without releasing it made a right click. And here is a result:
With arrows I sign the row where I clicked with right button, where WM_CAPTURECHANGED
message sent. This message according to documentation is:
Look on next line with arrow. The handle of the next window is 0, so there is no any window. So this means, like a simple command: You lost a capture on mouse.
Hope this helps.