Ignoring mouse event from contained controls

  • Thread starter Thread starter ronchese
  • Start date Start date
R

ronchese

Hello!

I have a UserControl that have two other controls inside it. I need to set a
different border color for my UserControl when the mouse enters it, and
restore the border color when the mouse leaves it.

The problem is, when the mouse passes in a contained control, the
UserControl raises a MouseLeave and the border is restored back, although
the mouse, for the customer, is yet inside the UserControl.

It's possible I do the UserControl ignores all mouse events for his
contained controls? Or there is another approach?

Cesar
 
Add the child control to your handles as well.

For instance if you have a panel named Panel1 with a label named Label1
contained in it you can use:
Private Sub Panel1_MouseEnter(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Panel1.MouseEnter, _



Label1.MouseEnter

Panel1.BackColor = Color.Black

End Sub


Then do the same thing for the mouseleave event
 
Yeah, I did that already.

But that makes me paint the control everytime a contained control get the
focus, once the control is already painted with that status, because the
mouse is already inside it.

I was trying to get a way to ensure that border is painted just one time per
MouseEnter and just one time per MouseLeave. It can be performatic when
eventually I start painting hard drawings on there.

But thanks anyways, for the response.

Cesar
 
What kind of controls are they? Can you set the enabled property of the
child controls to False? If so, this should keep it from triggering event.
 
Back
Top