Passing mouse events over to the parent
-
Hi there, I have a simple user control that I would like to handle mouse events for (such as mouse down etc.). My user control has a couple of Panel objects on it, and these are receiving the mouse events I am interested in. I would like the parent user control to handle the events instead of the panel objects (or anything I insert onto the parent). I understand that I can assign the panel (and any other child object's) mouse event handlers to be the event handler I wrote for the parent, and that works as desired, but I'm wondering if there is a better solution? So my question is: to have mouse events handled by a parent object, do I need to have each child object's event handler set to be the parent handler code, or is there a property I can set to automatically pass the event to the parent? Many thanks.
- Dy
-
Hi there, I have a simple user control that I would like to handle mouse events for (such as mouse down etc.). My user control has a couple of Panel objects on it, and these are receiving the mouse events I am interested in. I would like the parent user control to handle the events instead of the panel objects (or anything I insert onto the parent). I understand that I can assign the panel (and any other child object's) mouse event handlers to be the event handler I wrote for the parent, and that works as desired, but I'm wondering if there is a better solution? So my question is: to have mouse events handled by a parent object, do I need to have each child object's event handler set to be the parent handler code, or is there a property I can set to automatically pass the event to the parent? Many thanks.
- Dy
Hi, I would try setting
Control.Enabled=false;
for those Controls that should not react on keyboard and mouse. This would influence the rendering for some, not for Panel AFAIK. :)Luc Pattyn [Forum Guidelines] [My Articles]
Voting for dummies? No thanks. X|
-
Hi, I would try setting
Control.Enabled=false;
for those Controls that should not react on keyboard and mouse. This would influence the rendering for some, not for Panel AFAIK. :)Luc Pattyn [Forum Guidelines] [My Articles]
Voting for dummies? No thanks. X|
-
That technique works well, thank you Luc. As you said, it influences some controls paint jobs. Whilst that doesn't affect the control I'm working on at the moment, it probably will in the future, so I will continue to look for another means too.
- Dy
I've had this problem too when the question came up whether a control could give users a possibility to drag child controls around. Either you don't use controls at all and do everything in the OnPaint method (which is pure hell), or you have to suscribe to the mouse events of all child controls. So far I haven't come up with anything better than a central ChildControl_MouseDown handler and a call in the constructor (after InitializeComponent) like foreach (control in this Controls) control.MouseDown+=ChildControl_MouseDown