What can I know what component is getting focus?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?VmFuZXNzYQ==?=

    What can I know what component is getting focus?

    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
  • Peter Duniho

    #2
    Re: What can I know what component is getting focus?

    On Thu, 15 May 2008 10:03:01 -0700, Vanessa
    <Vanessa@discus sions.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.FromHan dle() to resolve back to the actual Control instance that's
    relevant.

    Pete

    Comment

    • Kalpesh

      #3
      Re: What can I know what component is getting focus?

      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

      Comment

      Working...