How to capture mouse entering/leaving form?

Djltd111

New member
Joined
Nov 21, 2009
Messages
1
Programming Experience
Beginner
Hi there, I'm new to VB and I apologize if I did not post this question in the right place.

I want to have a counter that measures when a mouse enters/leaves a form. To that extent I used the .mouseenter/.mouseleave commands. This works to an extent. the problem is that moving the mouse over any controls inside a form count as existing it- I dont want this. Is there a way to define the controls as a part of the form? meaning- if the mouse was over one of my labels- it would count as being within the form. a less elegent way to measure form access could be to use the form positioning, and define capture any mouse movement within it. Either solution would be very appreciated.

-Avner
 
I'd say that you have two choices:

1. Test the mouse pointer location on the form's MouseEnter and MouseLeave events and only update your count if it's at the edge of the form.

2. Handle the MouseEnter and MouseLeave event for the controls too and update the count in the opposite way, e.g. If you increment the enterCount for the form on the form's MouseEnter event the you decrement it on the controls' MouseLeave events.
 
Back
Top