Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 351
  • 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
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone 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