I am trying to add an event handler for each control in my form. The form is a simple info window that appears, and clicking anywhere on it does the same (like an Outlook email reminder.) For this, I wrote a recursive method to add a handler MouseClickfor each control, as follows:
private void AddMouseClickHandler(Control control, MouseEventHandler handler)
{
control.MouseClick += handler;
foreach (Control subControl in control.Controls)
AddMouseClickHandler(subControl, handler);
}
However, if I wanted to add a handler for all events MouseDownand MouseUp, I would have to write two more methods. I am sure there is a way around this, but I cannot find it. I need a method like:
private void AddRecursiveHandler(Control control, Event event, EventHandler handler)
{
control.event += handler;
foreach (Control subControl in control.Controls)
AddRecursiveHandler(subControl, event, handler);
}