C#-FORM Way to reference textbox that holds cursor?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ntabb
    New Member
    • Sep 2008
    • 7

    #1

    C#-FORM Way to reference textbox that holds cursor?

    I'm writing a function to cut the information out of a textbox when a button is pressed. There are many textboxes on the form, and I only want to cut the information in the box that has the cursor. I really don't want to look for the cursor in each textbox in each level of the form.

    Is there a way to reference the "current" textbox?

    Thanks,
    NT
  • Plater
    Recognized Expert Expert
    • Apr 2007
    • 7872

    #2
    Well, when you click a button, the cursor LEAVES the textbox it was in, making NO textbox the current textbox. So you might want to re-think how you do that.

    Possibly using the onFocus() and onBlur() events in javascript?

    Comment

    • ntabb
      New Member
      • Sep 2008
      • 7

      #3
      Good point. I'm looking into the onFocus now....

      Comment

      • tlhintoq
        Recognized Expert Specialist
        • Mar 2008
        • 3532

        #4
        Maybe keep a tracking variable. At each TextBox Focus Enter event update the tracking variable to the new TextBox control. Then when you hit the magic key, even if you leave the TextBox in question you will still know which control last held the focus.

        All the TextBoxes can go to the same event handler with something like
        Control myTracker = (Control)sender ;

        Comment

        Working...