Results 1 to 8 of 8

Thread: Keep focus on one text box

  1. #1

    Thread Starter
    Member
    Join Date
    Nov 2005
    Posts
    38

    Keep focus on one text box

    hi there

    Im looking to keep focus in my first text box even after i have selected on different options.

    basically i have 10 command buttons giving different info into the txtNamebox.Text

    VB Code:
    1. Private Sub cmdIcon_click(Index As Integer)
    2.  
    3.     Select Case Index
    4.         Case 0
    5.             txtNamebox.Text = txtNamebox.Text + Format$("1")
    6.         Case 1
    7.             txtNamebox.Text = txtNamebox.Text + Format$("2")

    But after selecting one of them command buttons , i have to manually select the first text box again to type into.
    .Please help/


    I have the first text box as tab index 0 and the rest disabled but that doesnt work

  2. #2
    PowerPoster Keithuk's Avatar
    Join Date
    Jan 2004
    Location
    Staffordshire, England
    Posts
    2,236

    Re: Keep focus on one text box

    VB Code:
    1. Private Sub cmdIcon_click(Index As Integer)
    2.  
    3. Select Case Index
    4.         Case 0
    5.             txtNamebox.Text = txtNamebox.Text + Format$("1")
    6.         Case 1
    7.             txtNamebox.Text = txtNamebox.Text + Format$("2")
    8. End Select
    9.  
    10. txtNamebox.SetFocus
    11.  
    12. End Sub
    Keith

    I've been programming with VB for 25 years. Started with VB4 16bit Pro, VB5 Pro, VB6 Pro/Enterprise and now VB3 Pro. But I'm no expert, I'm still learning.

  3. #3

    Thread Starter
    Member
    Join Date
    Nov 2005
    Posts
    38

    Re: Keep focus on one text box

    ahaha setFocus man you rock thanks

  4. #4

    Thread Starter
    Member
    Join Date
    Nov 2005
    Posts
    38

    Re: Keep focus on one text box

    that worked great how ever i need it to goto the end of the text box no matter what data is in there.

    thanks

  5. #5
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,614

    Re: Keep focus on one text box

    VB Code:
    1. Private Sub Text1_GotFocus()
    2.     Text1.SelStart = Len(Text1)
    3. End Sub
    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." — Charles F. Kettering

    Read articles on My Blog101 LINQ SamplesJSON ValidatorXML Schema Validator"How Do I" videos on MSDNVB.NET and C# ComparisonGood Coding PracticesVBForums Reputation SaverString EnumSuper Simple Tetris Game


    (2010-2013)
    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

  6. #6

    Thread Starter
    Member
    Join Date
    Nov 2005
    Posts
    38

    Re: Keep focus on one text box

    sorry maybe im not explaining this right,

    After i select a command button i want i too automatically go back to Textbox 1 > and setfocus to the end of the Textbox1

  7. #7

    Thread Starter
    Member
    Join Date
    Nov 2005
    Posts
    38

    Re: Keep focus on one text box

    ahh yer i see what i needed to do now .

    thanks alot

  8. #8
    PowerPoster Keithuk's Avatar
    Join Date
    Jan 2004
    Location
    Staffordshire, England
    Posts
    2,236

    Re: Keep focus on one text box

    VB Code:
    1. Private Sub Command1_Click()
    2.  
    3. Text1.SelStart = Len(Text1.Text)
    4. Text1.SetFocus
    5.  
    6. End Sub
    Keith

    I've been programming with VB for 25 years. Started with VB4 16bit Pro, VB5 Pro, VB6 Pro/Enterprise and now VB3 Pro. But I'm no expert, I'm still learning.

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