Detect when mouse enters/leaves form

  • Thread starter Thread starter Terry Wahl
  • Start date Start date
T

Terry Wahl

I need way to detect when the mouse enters/leaves a form.
MouseEnter/MouseLeave events will not work because I receive a MouseEnter
event when the mouse moves into the form but once the mouse moves over a
control contained in the form a MouseLeave event is fired. Is there an easy
way to do this?

Thanks for your help,
Terry
 
You could service the mouseleave and see if the mouse is actually over the
form using the static Control.MousePosition property and check to see if it
maps to the rectangle defined by your main window.

You could also subscribe to the MouseEnter and MouseLeave events of all
child controls and keep a flag accordingly.

--
--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.
 
Back
Top