I have Form subclass with handlers for MouseHover
and MouseLeave
. When the pointer is on the background of the window, the events work fine, but when the pointer moves onto a control inside the window, it causes a MouseLeave
event.
Is there anyway to have an event covering the whole window.
(.NET 2.0, Visual Studio 2005, Windows XP.)
On your user control create a mousehover Event for your control like this, (or other event type) like this
On your WinForm which hosts the UserControl have this for the UserControl to Handle the MouseOver so place this in your Designer.cs
Which calls this method on your WinForm
Where ThumbImage is the type of usercontrol
There is no good way to make MouseLeave reliable for a container control. Punt this problem with a timer:
When the mouse leave event is fired one option is to check for the current position of the pointer and see if it within the form area. I am not sure whether a better option is available.
Edit: We have a similar question which might be of interest to you. How to detect if the mouse is inside the whole form and child controls in C#?
Ovveride the MouseLeave event to not trigger so long as the mouse enters a child control