• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 354
  • Last Modified:

highlighting Visual Basic textbox

Is there a way of highlighting a textbox when the textbox receives the focus?  

I have a textbox with a value in it and when I tab into that textbox, I want to highlight it so that I can just type and it will erase the text that was in there and replace it with the new text.  

Thanks
0
Taitor
Asked:
Taitor
  • 5
  • 4
1 Solution
 
kamallCommented:
Use:

Private Sub Text1_GotFocus()

    Text1.SelLength = Len(Text1)

End Sub

Regards.
0
 
kamallCommented:
Better, use this code:

Private Sub Text1_GotFocus()

    Text1.SelStart = 0
    Text1.SelLength = Len(Text1)

End Sub

0
 
MarineCommented:
this is simple but maybe better approaches found.
this goes into getfocus of textbox event
Text1.SelStart = 0
Text1.SelLength = Len(Text1.Text)
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
MarineCommented:
GRR i hate when that happends.
0
 
kamallCommented:
Marine,
What is the difference between my code and yours!!!
0
 
MarineCommented:
absolutely none. the thing is i had a window with a question open earlier but entered results later then you did so i didn't see your posted answer before i submited mine.
0
 
TaitorAuthor Commented:
kamall

That seems to work good.

Thanks  
0
 
kamallCommented:
Taitor,
you are welcome.

Marine,
It always happens to all of us :-)
0
 
MarineCommented:
i like this board, i learn a lot from it so if i can help in any way its good for me even if someone beats me to it :) I read your profile you got lots of years experience thats really good. Maybe some day i am going to be just as an experienced :-). Catch you later.
0
 
kamallCommented:
Marine,
I hope you all the success in your future :-)
0

Featured Post

Take Control of Web Hosting For Your Clients

As a web developer or IT admin, successfully managing multiple client accounts can be challenging. In this webinar we will look at the tools provided by Media Temple and Plesk to make managing your clients’ hosting easier.

  • 5
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now