All your questions are reduced to a simple thing: you compose some children controls in some parent controls and want to introduce and expose some new events at the level of parent control, as the children are apparently hidden from the used of the user control.
There is nothing special in this situation. You simply need to work "by definition": add an event handler to the invocation list of some child's event; in the handler implementation, invoke the parent's event. Lets look at it on the simple example of one child and its
Click
event:
public class ChildEventArgs : System.EventArgs {
internal ChildEventArgs(Control child) { this.Child = child; }
public Child { get { return this.child; } }
Control child;
}
public partial class MyParentControl {
public MyParentControl() {
child.Click += (sender, eventArgs) => {
if (ChildClicked != null)
ChildClicked.Invoke(this, new ChildEventArgs(child));
};
Controls.AddChild(child);
}
public event System.EventHandler<ChildEventArgs> ChildCliked;
SomeControlType child = new SomeControlType();
}
For an array (but it should be some collection instead, I presume), you basically do the same, but dynamically. Most likely, you need to add the handler to the invocation lists of children events when you add a child, but in this case, you will also need to remove a handler ("-="), to cover rare cases when a child is removed but still used outside of your control, can be added again, etc., so you would avoid multiple handlers. You can also develop special children control types to improve it. I'll leave all that for your home exercise. :-)
—SA