Repeated MouseHover events in C#
Due to a quirk in the way Windows handles events, once a mouse hover event has been triggered on a windows form control, another event cannot be triggered until the mouse leaves and re-enters the control. Sometimes you might need to process more than one MouseHover event, for example if you have a user control which has draws shapes on itself. As long as you have a record of where the shapes are (by storing them in a collection), you can use the method below as a workaround.
I used this to display a tooltip, so to prevent the MouseHover event being spammed, action is only taken when my tooltip is not visible. private const uint TME_HOVER = 0x00000001; private const uint TME_LEAVE = 0x00000002; [DllImport("user32.dll")] public uint cbSize; public IntPtr hwndTrack; } Rectangle currentActiveShape = new Rectangle(); // the currently active shape (over which the mouse is hovering) foreach(Rectangle rect in myShapeCollection) { toolTip.Hide(); } currentActiveShape = rect; // Set location here } } }; trackMouseEvent.hwndTrack = ((Control)sender).Handle; trackMouseEvent.dwFlags = TME_HOVER; trackMouseEvent.dwHoverTime = HOVER_DEFAULT; toolTip.Show(); } }; Due to a quirk in the way Windows handles events, once a mouse hover event has been triggered on a windows form control, another event cannot be triggered until the mouse leaves and re-enters the control. Sometimes you might need to process more than one MouseHover event, for example if you have a user control which has draws shapes on itself. As long as you have a record of where the shapes are (by storing them in a collection), you can use the method below as a workaround.
