Get the focused control

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

Is there a way to get the control that has the focus on a form?

The following code should at least compile but VS says some path don't have
a return value. Any way to bypass the compiler on this?

But maybe someone has a better way?

Thanks,
Sitar.

===

static public Control GetFocusedControl(Control parent)
{
if (parent.Focused)
{
return parent;
}
else
{
if (parent.Controls.Count>0)
{
foreach (Control c in parent.Controls)
{
return GetFocusedControl(c);
}
}
else
{
return null;
}
}
}
 
Nope. It came straight out of my tired brain! :)
Your code is actually slightly different. I'm going to try that. Thanks.

Sitar.
___
 
Back
Top