Hi

I need to catch a Control-Enter keyboard input on a UserControl and any of
it's children, but it seems only the actual focused control gets the events.
So I looked around the net and didn't find a solution. I came up with my own
solution, which involved cycling through all the children and attaching a
KeyDown event.


public void Init()
{
    RecursivelyAddEvent(this.Controls, 0);
}

public void RecursivelyAddEvent(ControlCollection controls, int level)
{
    foreach(Control ctrl in controls)
        {
            ctrl.KeyDown += EmailEditor_KeyDown;
            if(level < 3)
                RecursivelyAddEvent(ctrl.Controls, level+1);
         }
}

It works, but there must be a better solution?

Thanks
Noobie Winforms Dude

Reply via email to