Question with mouse message!

Well, suppose we have two panel controls, one is A, one is B. B is docked in A and coverd all client area of A. So now, any mouse event(MouseEnter, MouseMove...) will just sent to B not A. So the question is that is there any way to let mouse event on the child control send to it's parent control?
If the control just have one child control, that's easy, I just subscribe the child control's mouse event. But If the control have many child control and any child control have some child control, and .... . that's bother.
[546 byte] By [winprock] at [2007-11-20 10:56:35]
# 1 Re: Question with mouse message!
It sounds like you are looking for something like an event bubble, as far as I know that's only available in web environment. So, I think your options are limited to what you seem to be dreading and that is to have the parent subscribe to all of its children's interesting events. . .
trenches at 2007-11-9 11:36:03 >
# 2 Re: Question with mouse message!
Whats about hooking the mouse event ?
or having a loop that subscribes all controls mouse events to the parental form using

foreach(Control c in this.Controls ){
try{
c.MouseMove += new MouseEventHandler(c_MouseMove);
c.MouseUp += new MouseEventHandler(c_MouseUp);
c.MouseDown += new MouseEventHandler(c_MouseDown);
}
}

private void c_MouseMove(object sender, MouseEventArgs e){
this.OnMouseMove(e);
}
private void c_MouseUp(object sender, MouseEventArgs e){
this.OnMouseUo(e);
}
private void c_MouseDown(object sender, MouseEventArgs e){
This.OnMouseDown(e);
}
Then in the delegate calling OnMouseMove or OnMouseUp, OnMouseDown depending which delegate it is. This should handle the events to the parental Form. And isn't to much of code.

Then you only have to code by hand when controls are on controls again. But this can easily be done creating Userdefined controls which collects controls which are built together to a new control and this way you again have single one MouseMove event for your new usercontrol.

Hooking is per sure less work but is done using API calls using unmanaged code.

So decide what you prefer.
JonnyPoet at 2007-11-9 11:37:03 >