Welcome to WindowsClient.net | Sign in | Join

Here are some frequently asked questions about Windows Forms and their answers.

Windows Forms FAQs

Why do I not receive MouseLeave messages in a Control in a Form?

This usually happens when a Control doesn't know that the mouse has left its bounds following a mouse enter. This results in the Control not throwing a MouseLeave event for subsequent mouse moves over it.

This is possible if you performed some operation when the mouse was within a Control that made it lose its mouse capture, for example, opening a top-level window over the Control such that the mouse is now over this new window.

To work around this problem send a WM_MOUSELEAVE manually to the original Control before the offending operation.

class NativeMethods 
{ 
  [ DllImport( "user32.dll", CharSet=CharSet.Auto ) ] 
  extern public static IntPtr SendMessage(IntPtr hWnd, int msg,
    IntPtr wParam, IntPtr lParam) ; 
}
 
// Send a WM_MOUSELEAVE manually to a window. 
NativeMethods.SendMessage( control.Handle,
  NativeMethods.WM_MOUSELEAVE, IntPtr.Zero, IntPtr.Zero );

Contributed from George Shepherd's Windows Forms FAQ



Page view counter