即使光标不在控制范围内也接收鼠标移动 [英] Receive mouse move even cursor is outside control

查看:74
本文介绍了即使光标不在控制范围内也接收鼠标移动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我做了类似Control中的滚动条的操作.一切都很好,但是当光标离开控制区域时,不再接收到OnMouseMove.

I did something like scrollbar from Control. Everything is fine, but when cursor leaves control area, OnMouseMove is not received anymore.

使用标准的Windows滚动条时,即使鼠标光标位于控件的表面之外,也可以使用它.

When you use standard windows scrollbar, you can use it even if mouse cursor is outside the control's surface.

为避免这种情况,我唯一的想法是从屏幕上获取光标位置,然后计算屏幕上的滚动条位置,并使用计时器或其他工具来更新我的Control.但这听起来很丑陋.

To avoid this, the only idea I have, is get cursor position from screen, then calculate scrollbar position on screen, and use timer or something to update my Control. But it sounds very hard and ugly.

有什么想法要解决吗?

我的意思是Control而不是UserControl.

它接收鼠标!我有代码错误,我在MouseMove方法中调用了MouseDown,但是在MouseDown中,我有X/Y约束,如果X <0等,它将强制返回

It receives mouse! I had bug in code, I called MouseDown in MouseMove method, but in MouseDown I had X/Y constraint that will force to return if X<0 etc.

推荐答案

您要查找的内容称为mouse capture,并在此处进行了描述:

What you are looking for is called mouse capture and is described here:

http://msdn.microsoft.com /en-us/library/ms171545(v=vs.80).aspx

简而言之:

  • 在控件中按下鼠标,即可捕获"鼠标输入
  • 然后,只要没有其他人抓住鼠标,您将收到所有鼠标移动事件,甚至是您控制范围之外的事件
  • 如果您不再需要数据,则可以释放捕获,可以选择在"OnMouseUp"中

这篇关于即使光标不在控制范围内也接收鼠标移动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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