I have code that allows a user to hover over a control, and it will respond. However, I'd like the hovering to fire a little quicker. Is there a way to speed up the hover reaction?
相关问题
- Sorting 3 numbers without branching [closed]
- Graphics.DrawImage() - Throws out of memory except
- Why am I getting UnauthorizedAccessException on th
- 求获取指定qq 资料的方法
- How to know full paths to DLL's from .csproj f
If you use the
ToolTip
component for this purpose, you can set itsInitialDelay
property to a value smaller than the default 500 (half a second).By the way, the
AutoPopDelay
andReshowDelay
properties are also useful, determining the display time and the delay upon the mouse re-entering the control's client area, respectively.You can try an alternative that works, that is not using a mouse hover event and instead following the first answer on this site. Otherwise if you do change it, it will effect all applications, not just yours.
There is an intentional time delay of
SystemInformation.MouseHoverTime
milliseconds before theMouseHover
event is generated, as a simple alternative you can use theMouseEnter
event instead, which will trigger immediately.Yes you can. The hover in Windows Forms is not following the global system setting and it has been set in
NativeMethods.TRACKMOUSEEVENT
to 100 milliseconds in thedwHoverTime
field.Then in
WndProc
method of the native window of the control,WM_MOUSEMOVE
has been trapped to callTrackMouseEvent
which in turn cause aWM_MOUSEHOVER
. You can see the source code here.So you can handle
WM_MOUSEMOVE
and callTrackMouseEvent
by setting desired timeout for mouse hover asdwHoverTime
field of theTRACKMOUSEEVENT
. Also handleWM_MOUSEHOVER
and raise a custom event likeMyMouseHover
.Then you can easily handle this custom
MyMouseHover
event.Notes
The system-wide
SystemInformation.MouseHoverTime
setting is used forToolTip
. But theMouseHover
event is following the value ofdwHoverTime
field ofNativeMethods.TRACKMOUSEEVENT
which is set to 100 milliseconds.You can find a similar implementation in my post for handling hover event on title bar of a form: Handle Mouse Hover on Titlebar of Form.
As another option I also tried setting value of
dwHoverTime
field of the privatetrackMouseEvent
field of the control and this solution also seems to be working.You can find VB version of the code here.