Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Determining the Active Control

37 views
Skip to first unread message

Joe Hanna

unread,
Jan 18, 2004, 12:03:27 AM1/18/04
to
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

Tim Wilson

unread,
Jan 18, 2004, 1:30:06 AM1/18/04
to
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

"Joe Hanna" <zo...@msdn.com> wrote in message
news:eAEi2AY3...@TK2MSFTNGP12.phx.gbl...

Joe Hanna

unread,
Jan 18, 2004, 2:15:23 AM1/18/04
to
Thanks Tim

"Tim Wilson" <Tim_Wilson@[DieSpamDie]Rogers.com> wrote in message
news:O1DBxwY3...@TK2MSFTNGP10.phx.gbl...

0 new messages