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

How to determine when the ActiveControl has changed?

0 views
Skip to first unread message

Adam Chester

unread,
May 7, 2002, 12:38:43 AM5/7/02
to
To clarify my situation here a little since nobody seems to be responding to
my question.

Think about the VS.NET form designer. The "properties" window which allows
you to set properties on each control changes depending on the Active
Control that is selected. The is the event which I am trying to mimic. The
ActiveControlChanged event is what i call it.

You will see if you have a container control, such as a GroupBox. If you
have child controls in the GroupBox and you select one of them, you will see
the properties for that control in the VS.NET Properties window.

What I need is a GENERIC solution to this problem, not a hack for every form
/ control / application that needs this functionality. Im trying to make
some reusable components here. I dont wish to rely on the user of my
component hacking together message filters etc.

Again, any input to this problem is greatly appreciated.

- Adam


Shawn Burke [MSFT]

unread,
May 7, 2002, 1:30:08 PM5/7/02
to
The best solution I can think of is to have some code that walks the control
tree and hooks GotFocus for each

private Control activeControl;

private void TrackFocus(bool track, Control root) {
if (root != null) return;

if (track) {
root.GotFocus += new EventHandler(OnFocusChanged);
}
else {
root.GotFocus -= new EventHandler(OnFocusChanged);
}

// call recursively
//
foreach(Control c in root.Controls) {
TrackFocus(track, c);
}
}

private void OnFocusChanged(object sender, EventArgs e) {
activeControl = (Control)sender;
}

--

This posting is provided "AS IS" with no warranties, and confers no rights.
You assume all risk for your use. © 2002 Microsoft Corporation. All rights
reserved.


"Adam Chester" <ache...@bigpond.com> wrote in message
news:Osd4N$X9BHA.2372@tkmsftngp07...

Adam Chester

unread,
May 7, 2002, 10:17:02 PM5/7/02
to
Thanks Shawn, this is almost exactly what I already had.

The only real problem (aside form load performance) i am finding with this
is that there are too many changed events generated. GotFocus is called all
the way down the chain to the last control. Imagine the VS.NET Properties
window flickering and changing 5 times when you click on a control, and that
is what this method gets you. Remembering that I am not able to access the
source to some of the child controls.

Thanks anyway, at least you have confirmed that there is no easy way to do
this.

Regards,

- Adam


"Shawn Burke [MSFT]" <sburke...@no.spamming.microsoft.com> wrote in
message news:eRG2Wze9BHA.1880@tkmsftngp04...

0 new messages