Results 1 to 8 of 8

Thread: [RESOLVED] [2005] SetFocus on a text box?

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jun 2006
    Posts
    250

    Resolved [RESOLVED] [2005] SetFocus on a text box?

    Hi all,

    How do you set focus on a text box programiticaly in vb.net 2005?

  2. #2
    Frenzied Member
    Join Date
    Jan 2001
    Posts
    1,374

    Re: [2005] SetFocus on a text box?

    TextBox1.Focus

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Jun 2006
    Posts
    250

    Re: [2005] SetFocus on a text box?

    Hi robertx,

    How do I set focus on a text box and also highlight the text within it?

  4. #4
    Frenzied Member
    Join Date
    Jan 2001
    Posts
    1,374

    Re: [2005] SetFocus on a text box?

    TextBox1.Focus
    TextBox1.SelectAll

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Jun 2006
    Posts
    250

    Re: [2005] SetFocus on a text box?

    excellent, thank you for you help.

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: [RESOLVED] [2005] SetFocus on a text box?

    This is from the MSDN help topic for the Control.Focus method:
    Focus is a low-level method intended primarily for custom control authors. Instead, application programmers should use the Select method or the ActiveControl property for child controls, or the Activate method for forms.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  7. #7
    Fanatic Member bgmacaw's Avatar
    Join Date
    Mar 2007
    Location
    Atlanta, GA USA
    Posts
    524

    Re: [2005] SetFocus on a text box?

    Quote Originally Posted by Giraffe Frenzy
    Hi robertx,

    How do I set focus on a text box and also highlight the text within it?
    It just so happens I posted an article about this yesterday. There is a little .NET event order quirk that you have to be aware of when selecting text in code. That is you must put your SelectAll code in both the Enter and MouseDown events of the control. If you don't, the mouse click will change your selection. This is different than the way VB6 behaved so watch out for it.

  8. #8
    Registered User nmadd's Avatar
    Join Date
    Jun 2007
    Location
    U.S.A.
    Posts
    1,676

    Re: [2005] SetFocus on a text box?

    Quote Originally Posted by bgmacaw
    It just so happens I posted an article about this yesterday. There is a little .NET event order quirk that you have to be aware of when selecting text in code. That is you must put your SelectAll code in both the Enter and MouseDown events of the control. If you don't, the mouse click will change your selection. This is different than the way VB6 behaved so watch out for it.
    Was searching for this exact answer wondering why clicking in my text box didn't fire the Enter event. Thanks for the post!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width