鼠标移动捕获 [英] Mouse movement capture

查看:126
本文介绍了鼠标移动捕获的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序开放的至极模式窗体的ShowDialog方法。
一旦显示这种形式我想捕捉即使光标的形式外的鼠标移动。
我怎样才能捕捉到鼠标移动?我看到的捕获性能的东西,但我不能设法使其工作。

I have an application wich open a modal form with the ShowDialog method. Once this form is displayed I want to capture the mouse movement even if the cursor is outside the form. How can I capture the mouse movement? I saw something with the Capture property but I cannot manage to make it work.

我想如果表单以外的鼠标移动的通知。

I want to be notified if the mouse move outside the form.

推荐答案

拍摄属性是正确的做法,但也有一定的局限性。

The Capture property is the correct way, but there are some limitations.


  • 只有前台窗口可捕获鼠标

  • 鼠标捕获可以由系统

  • Win32 API函数 SetCapture 的其他部分被禁止获取每次重置鼠标事件occours。我认为也适用于.NET。

  • Only the foreground window can capture the mouse
  • Mouse capturing can be disabled by other parts of the system
  • The Win32 API function SetCapture gets reset everytime a "mouse up" event occours. I assume that also applies for .NET.

见的注释部分的 拍摄属性。

当鼠标被捕获,您会收到一般的事件,但与更广泛的鼠标坐标范围(例如负X位置,如果鼠标离开了捕获控制)

When the mouse is captured, you'll receive the usual events but with a wider mouse coordinate range (for example a negative X position, if the mouse is left of the capturing control)

鼠标捕获是脆弱的,因为它是全球性的。检查是否有其他的方式来处理某些事件。也许鼠标离开的MouseEnter 事件足以在你的情况。

Mouse capturing is fragile, because of it's global nature. Check if there are other ways to handle certain events. Perhaps the MouseLeave or MouseEnter events are enough in your case.

这篇关于鼠标移动捕获的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆