Get the focused control

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;
}
}
}
 
G

Guest

Nope. It came straight out of my tired brain! :)
Your code is actually slightly different. I'm going to try that. Thanks.

Sitar.
___
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top