开发者

MouseEnter and MouseLeave Event not raising in user control

Here开发者_StackOverflow中文版 is the problem:

  • I have a simple c# form
  • I have a simple c# user control containing a picturebox and other button.
  • My form contains one instance of the user control.
  • I want that when the user do a mouseEnter in the picture box, the mouse cursor change and when the user do a mouseLeave of the picturebox, the mouse go back to normal.

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!


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜