mouse events when the mouse is on a "child control"

  • Thread starter Thread starter red
  • Start date Start date
R

red

mouse events when the mouse is on a "child control"

hi everyone;
my problem:
I have a userControl
in this usercontrol, I have a child control (a button)

when the mouse moves over the userControl, I can detect the movement using
MouseMove event.
the problem is when the mouse is on the child control : I can t detect
anything when the mouse move. userControl don t recieve the MouseMove event.

I did many search on this problem, but solutions I found are not elegant:
1- using hooks (not a part of .net platform)
2- the child control report the mouse movement to the parent control (the
userControl here)

please, can u explain me how to solve this problem?
thnks

n.b.: sorry for my english
 
System always gives the previlage to listen mouse events to the last
entered control. For windows forms as you know there is a property
KeyPreview which enables Forms to receive mouse events before the
contained controls. If you make the user control listen the mouse
events; then user control can handle the mouse move. For instance, if
you press the mouse button when the mouse is on the uc, and start to
move you will see that uc is receiving mouse move events even if the
mouse is over the child control.
So you must manually mouse event listening previlage to the uc like
mouse down automatically does it for you.
 
For instance in the UserControl's code window handle the mouse_enter
event and write
this.Capture = true;
You will see that mouse move is captured bu usercontrol even if the
mouse is on the child control.

Hope this helps..
 
Back
Top