• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 356
  • 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
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

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