MouseEnter and MouseLeave Event not raising in user control

Here is the problem:

What is happening now is that the events are not fired at all. I put break point into MouseOver, MouseEnter, MouseMove, MouseLeave, etc and none of thems fired. It's the first time I have this problem in C#.

I think it has something to do with the "routed event" but I can't figure it out. If there is another way to achieve what I'm doing, this will also be considered a solution. What is important is that at the end, the user control will be the master of the mouse cursor over his "territory".

Thanks in advance!

Upvotes: 4

Views: 4762

Answers (2)

Serge Wautier
Serge Wautier

Reputation: 21878

As InBetween wrote, PictureBox.MouseXXX should be firing. You can trap those in your UserControl.

If you want the event to be fired on behalf of UserControl, just disable the PictureBox. Be aware though that the event would fire for any mouse position over the UserContrl, not only the PictureBox.

Upvotes: 1

InBetween
InBetween

Reputation: 32770

What events are you using? The UserController.MouseEnter and UserController.MouseLeave events or the PictureBox.MouseEnter and PictureBox.MouseLeave events?

You should use the latter as the PictureBox will handle the event if the mouse enters the user controller directly through the PictureBox.

Upvotes: 2

Related Questions