Determining which control has input focus?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Dave Veeneman

    Determining which control has input focus?

    What's the best way to determine in code which control on a form has input
    focus?

    I'm programming an edit menu (the usual cut, copy, paste), which needs to
    target one of several text boxes on its form. Specifically, the menu needs
    to target the text box that has the input focus. For the moment I'm assuming
    there will be no controls on the form except the menu and the text boxes.

    I've found code to drive the clipboard edit methods. But none of the
    examples shows how to determine which text box has the input focus. They all
    assume the method there is only one text box on the form. So, what I'm
    puzzling over is this: Is there a simple way to determine which text box has
    the focus, or do I need to iterate through all controls on the form?

    Thanks.

    --
    Dave Veeneman
    Chicago


  • Miha Markic

    #2
    Re: Determining which control has input focus?

    Hi Dave,

    Does ActiveControl property help?

    --
    Miha Markic - RightHand .NET consulting & development
    miha at rthand com

    "Dave Veeneman" <davidv@nospam. com> wrote in message
    news:OXisEiiqDH A.1496@TK2MSFTN GP11.phx.gbl...[color=blue]
    > What's the best way to determine in code which control on a form has input
    > focus?
    >
    > I'm programming an edit menu (the usual cut, copy, paste), which needs to
    > target one of several text boxes on its form. Specifically, the menu needs
    > to target the text box that has the input focus. For the moment I'm[/color]
    assuming[color=blue]
    > there will be no controls on the form except the menu and the text boxes.
    >
    > I've found code to drive the clipboard edit methods. But none of the
    > examples shows how to determine which text box has the input focus. They[/color]
    all[color=blue]
    > assume the method there is only one text box on the form. So, what I'm
    > puzzling over is this: Is there a simple way to determine which text box[/color]
    has[color=blue]
    > the focus, or do I need to iterate through all controls on the form?
    >
    > Thanks.
    >
    > --
    > Dave Veeneman
    > Chicago
    >
    >[/color]


    Comment

    • Dave Veeneman

      #3
      Re: Determining which control has input focus?

      I found my answer. Forms (and other containers) have an ActiveControl
      property that returns the control with focus.


      Comment

      • Dave Veeneman

        #4
        Re: Determining which control has input focus?

        Yes-- thanks!


        Comment

        Working...