Event Handling: Overlapping Controls

Arokh

Centurion
Joined
Apr 11, 2006
Messages
124
Mouse Event Handling: Overlapping Controls

Hi

I have a panel which includes some controls.
Now I want the panel to hide if the mouse leaves its area.

But the mouseleave event is also fired when I hover the controls in it.
Is there some way to alter this behaviour,
for example that the child control in the panel passes the mousemovement to its parent,
so the parent (the panel) knows the mouse is still in its area?

I know some easy way to verify if the mouse is still in it,
but it would still be interesting to know if this is possible,
since this behaviour changes between different events.

I can for example add a handler for the Drag&Drop event of the form and
it also works if I "indirectly" drop something onto the Form child controls.
 
Last edited:
Re: Mouse Event Handling: Overlapping Controls

Any solution you would find would be a hack. In Windows Forms, each control is a window, so moving the mouse over a button in a panel fires the MouseLeave event because the mouse is leaving the panel's client window and moving into the button client window.

Drag&Drop events traverse up the ancestors and look for an object that can serve as a container.

If you already have an easy way to find out if the mouse is in a container, I would recommend using that. Other than that, inheriting from a panel class, creating a boolean field indicating whether or not the mouse has left and performing logic in a function that checks to see if the mouse is in any of the child controls would work.
 
Back
Top