By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,493 Members | 3,090 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,493 IT Pros & Developers. It's quick & easy.

What can I know what component is getting focus?

P: n/a
Hi all!

I have one combobox, two grids and nine textbox. All textbox are tab index
one following another. When I press tab I go to the next textbox. How can I
known if I click on another component, like the combobox?

Thank you!
Vanessa
Jun 27 '08 #1
Share this Question
Share on Google+
2 Replies


P: n/a
On Thu, 15 May 2008 10:03:01 -0700, Vanessa
<Va*****@discussions.microsoft.comwrote:
Hi all!

I have one combobox, two grids and nine textbox. All textbox are tab
index
one following another. When I press tab I go to the next textbox. How
can I
known if I click on another component, like the combobox?
Your question is somewhat ambiguous. The GotFocus and LostFocus events
will tell you about focus changes for specific controls. You can use
these to track focus changes among your own controls.

Unfortunately, when one control loses focus, the LostFocus event
associated with that doesn't tell you which control is getting focus, nor
does the GotFocus event tell you which control lost focus. However, if
you're subscribed to the approprite events for all of your controls, then
you can track that information yourself.

Barring that, you can override the WndProc() method and watch for
WM_KILLFOCUS and WM_SETFOCUS messages. These include a handle to the
"other" control window, which you may be able to pass to
Control.FromHandle() to resolve back to the actual Control instance that's
relevant.

Pete
Jun 27 '08 #2

P: n/a
I am not sure whether I understand the question correctly.
However, Form has ActiveControl property, which can help to find
control in focus.

Does that help?

Kalpesh
Jun 27 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.