Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Text Box - Auto Word Select 1

Status
Not open for further replies.

dsi

Programmer
Mar 13, 2000
964
US
There is a text box property AutoWordSelect in Office applications that I can not find in VB 6. This selects (highlights) the contents of a textbox as soon as it has focus. Is there a setting for this in VB? If not, does anyone have a slick routine to do this without creating an event for each text box in a form? I appreciate your help.
 
There's no property you can set to do this. However, you can create a routine that you can call from the textbox's gotfocus event. Something like this:<br>
<br>
Sub AutoSelect()<br>
Dim c As Control<br>
Set c = Screen.ActiveForm.ActiveControl<br>
If TypeOf c Is TextBox Then <br>
c.SelStart = 0<br>
c.SelLength = Len(c)<br>
End if <br>
set c = nothing<br>
End Sub<br>
<br>
Sub Text1_GotFocus()<br>
AutoSelect<br>
End sub <p>nick bulka<br><a href=mailto:nick@bulka.com>nick@bulka.com</a><br><a href= > </a><br>
 
Great answer, Nick! Tclere might want to make Text1_GotFocus() static and include a flag to prevent AutoSelect after the first GotFocus. (Otherwise, it could create misunderstandings with the users.) <p> <br><a href=mailto: > </a><br><a href= Vorpalcom home page</a><br>Send me suggestions or comments on my current software project.
 
That works great! The only problem is that I have to create a Got_Focus event for each text box. This could have been avoided if I arrayed the text boxes. Text1(0), Text1(1)... Since I did not do this, I have to handle each separately. Thanks for the help!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top