Hi Julien,

Re: question 1

Dominic is correct in that this is an example of event bubbling. Bubbling is supported on the client side of web applications in the HTML DOM with ((insert gasp)) javascript and other client side stuff. I, like Dominic, am unaware of event bubbling in the WinForms paradigm.

That said, I have found the following snippet (in C#) to be useful:

1
2
3
4
5
6
7
8
9
10
11
12
13
public void AssignEvents(Control theControl)
{
 theControl.MouseUp += new System.Windows.Forms.MouseEventHandler(this.somePanel_MouseUp);
 theControl.MouseMove += new System.Windows.Forms.MouseEventHandler(this.somePanel_MouseMove);
 theControl.MouseDown += new System.Windows.Forms.MouseEventHandler(this.somePanel_MouseDown);
 foreach (Control aControl in theControl.Controls)
 {
  aControl.MouseUp += new System.Windows.Forms.MouseEventHandler(this.somePanel_MouseUp);
  aControl.MouseMove += new System.Windows.Forms.MouseEventHandler(this.somePanel_MouseMove);
  aControl.MouseDown += new System.Windows.Forms.MouseEventHandler(this.somePanel_MouseDown);
  AssignEvents(aControl);
 }
}

For this example to work, assume that you have a Windows Form with all controls fully populated as needed, i.e. you won't modify containment/composition, etc. of the controls on the form. Then let somePanel be a control that has the requisite event handlers. In this case I am applying MouseUp, MouseMove and MouseDown. If you would like somePanel's children to all respond using somePanel's handlers, then after the form has been initialized, insert the following (in the constructor or elsewhere after all controls have been added):

1
AssignEvent(somePanel);

Also note that this can be applied to any control regardless of parentage/ancestry, i.e. if somePanel has the pertinent handlers, and controls panel2 and panel3 and all of their children need to respond using these handlers, the calls would be:

1
2
AssignEvent(panel2);
AssignEvent(panel3);

To perform this work in F# is an exercise that is left for the reader. ;)

Re: question 2

Check your Z-order of your docked controls on a form. As Greg mentioned, the order that controls are added to a form determine their initial Z-order.

If a control is dock filled, check that it is either "brought to the front" or "sent to the back" (by right clicking on the control in the appropriate designer). You should see the appropriate docking behavior (or <i>behaviour<i> ;) ). Also note that anchoring and docking can be used to "stack" controls in this manner, i.e. controls can be docked as top so that they dock to the next control above them (rather than the top of the form) as long as they are in descending Z-order. Regards, ---O p.s. No, I'm not a WinForm geek. These are just useful things I have done and must admit in public occasionally.

By on 8/15/2006 12:51 PM ()

Thanks a lot for your answers !

Julien.

By on 8/15/2006 1:21 PM ()

The thing you want in (1) is called "event bubbling" and I don't think WinForms supports it. If your UI is not dynamic or rich (i.e. few controls) the most expedient solution to (1) might be to have pc walk the UI tree after it is created and and listen to MouseHover/Click/etc. on its contained controls. Alternatively you could add event handlers to the contained controls to delegate UI events outwards to their parent controls--basically implement an event bubbling framework yourself.

By on 8/15/2006 9:14 AM ()

Hi Julien,

1. There may be a way for parent controls to receive UI events in addition to their children but I don't know what it is. If you are interested in getting the mouse position relative to the parent control from mouse events on the child controls then you can convert child-relative coordinates to parent-relative coordinates by calling PointToScreen on the child control and passing the result to PointToClient on the parent control.

2. The layout of controls in a container is dependent on the order in which the controls are added to the container. Controls that are added first are docked last. Add the panel first to the form.

Greg

By on 8/15/2006 9:04 AM ()
IntelliFactory Offices Copyright (c) 2011-2012 IntelliFactory. All rights reserved.
Home | Products | Consulting | Trainings | Blogs | Jobs | Contact Us | Terms of Use | Privacy Policy | Cookie Policy
Built with WebSharper