The problem formulation is not quite clear, but, based on many similar problems, this is a controversy between encapsulation of children of the custom or user control and the need for handling events dispatch to those children, without exposing the children themselves.
I could advice to handle (not "catch", handle) the events you need to expose internally and delegate them to other events accessible from outside. It would need a bit too much of extra work, but this is the whole idea of encapsulation of inner controls under the
fasade of a composite user or custom control. This is a simple illustration of the idea:
class MyUserControl : Control {
public MyUserControl() {
child.Click += (sender, eventArgs) => {
if (ChildClick != null)
ChildClick.Invoke(this, new System.EventArgs());
}
}
Button child = new Button();
public event System.EventHandler ChildClick;
}
Are you getting the idea? Same things go with the events which have more specialized event arguments types (derived from
System.EventArgs
, your own type or predefined in .NET FCL). The you use
public event System.EventHandler<concrete_event_args_type> SomeExternalEvent;
and transparently pass all data you carry in your event arguments type to the event invocation (second parameter of
Invoke
) for the child control's event.
If you have more than two levels of hierarchy in your custom or user control, you do the same, transparently passing events from the handler of inner control's event to its parent control. Just do the same work on more than one level.
—SA