In a C# Windows application there are 2 different mouse events, MouseEnter
and MouseHover
, which are both triggered when the cursor is over the object.
What is the difference between them?
The mouseenter() method is an inbuilt method in jQuery which works when mouse pointer moves over the selected element. Parameters: This method accepts single parameter function which is optional. It is used to specify the function to run when the mouseenter event is called.
This means that mouseleave is fired when the pointer has exited the element and all of its descendants, whereas mouseout is fired when the pointer leaves the element or leaves one of the element's descendants (even if the pointer is still within the element).
The mouseover event is fired at an Element when a pointing device (such as a mouse or trackpad) is used to move the cursor onto the element or one of its child elements.
Assuming you are in Windows Forms:
Mouse Enter occurs:
Occurs when the mouse pointer enters the control.
(MSDN)
Mouse Hover:
Occurs when the mouse pointer rests on the control.
A typical use of MouseHover is to display a tool tip when the mouse pauses on a control within a specified area around the control (the "hover rectangle"). The pause required for this event to be raised is specified in milliseconds by the MouseHoverTime property.
(MSDN)
To set MouseHoverTime globally (not recommended, see @IronMan84's link here for a better solution), you can use the SystemParametersInfo
function. Because thats a Win32 API call, you'll need PInvoke:
[DllImport("user32.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool SystemParametersInfo(SPI uiAction, uint uiParam, IntPtr pvParam, SPIF fWinIni);
Called as:
SystemParametersInfo(SPI.SPI_SETMOUSEHOVERTIME,
desiredHoverTimeInMs,
null,
SPIF.SPIF_SENDCHANGE );
Sigantures from PInvoke.NET: SystemParametersInfo, SPIF (Enum), SPI (Enum)
I didn't include the Enum
signatures here because they are so freaking long. Just use the ones on PInvoke.Net (linked above)
For complete information on the SystemParametersInfo API call and its parameters, see MSDN.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With