Detect when mouse enters/leaves form

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
 
B

Bob Powell [MVP]

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top