I'm trying to create User Control which will work like a rich button. It's supposed to have an effect on hover - I turn border on on MouseEnter and off again at MouseLeave. BUT, when I hover over label in my control, it fires Control.MouseLeave. Is there any way to prevent this?
A:
First, focus Enter and Leave are different events than MouseEnter and MouseLeave. Focus deals with keyboard input. MouseEnter and MouseLeave deals with where the mouse is right now.
Entering a nested control fires MouseLeave on the parent control. You can capture the mouse by setting the control's Capture property to true, but you may find that doesn't behave like you'd expect.
You might look at my post here. I had the same issue with nested controls. I opted to create a .NET equivalent of a mouse hook by calling Application.AddMessageFilter
.
Another option would be to remove the inner label control and draw the text manually it in the button's OnPaint.
Paul Williams
2009-09-02 14:21:44