Determining the Active Control

  • Thread starter Thread starter Joe Hanna
  • Start date Start date
J

Joe Hanna

Hi Everyone,

Just wondering how you can determine the Active Control on a form in the absence of the ActiveControl Member from .NET CF Forms?

Tried Google, but there was nothing on .NET CF.

Thanks in advance,
Joe
 
You're going to have to loop through the controls, starting with the main
Form, checking the Focused property to see which control has focus. Adding
the following property and helper method to your Form should do what you
want:

public virtual Control ActiveControl
{
get
{
return GetFocusedControl(this);
}
set
{
if (!value.Focused)
{
value.Focus();
}
}
}

private Control GetFocusedControl(Control parent)
{
if (parent.Focused)
{
return parent;
}
foreach (Control ctrl in parent.Controls)
{
Control temp = GetFocusedControl(ctrl);
if (temp != null)
{
return temp;
}
}
return null;
}

--
Tim Wilson
..Net Compact Framework MVP

Hi Everyone,

Just wondering how you can determine the Active Control on a form in the
absence of the ActiveControl Member from .NET CF Forms?

Tried Google, but there was nothing on .NET CF.

Thanks in advance,
Joe
 

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

Back
Top