private Control GetControlWithFocus(Control control)
{
// Does the provided control have the focus?
if (control.Focused)
return control;
else
{
// Check each child hierarchy in turn
foreach (Control child in control.Controls)
if (child.ContainsFocus)
return GetControlWithFocus(child);
return null;
}
}