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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

need a VB master's help...

Status
Not open for further replies.

Retar

Technical User
Feb 28, 2001
4
US
my program has many text field which needs to be filled out by the user. I want that each time the user navigate through the text fields using Tab or the mouse that the content of the text field gets highlighted. This way if the user wishes to change the data he doesn't need to erase then write , he can just type over...

thanks in advance !
 
on Text1_GotFocus event :

Text1.SelStart = 0
Text1.SelLength = Len(Text1)
 
If you have many controls you might want to use an array of controls, that way you don't need to put in the code for every textbox separately.

Mats
 
Or, place the following in the general section of the code

Private Function basHighlightActiveControl

[tab]Me.ActiveControl.SelStart = 0
[tab]Me.ActiveControl.SelLength = Len(Me.ActiveControl)

End Funnction

Place "basHighlightActiveControl" in the got focus of each 'text' control.

Dosen't do any "un'highlighting'?


MichaelRed
redmsp@erols.com

There is never time to do it right but there is always time to do it over
 
Isn't there a "FOR...EACH " clause??
 
Whit this code cou can clear all Textbox :

Dim Contrl As Control
For Each Contrl In Form1.Controls
If (TypeOf Contrl Is TextBox) Then Contrl.Text = ""
Next Contrl

Eric De Decker
vbg.be@vbgroup.nl

License And Copy Protection AxtiveX.

Download Demo version on my Site:
 
Eric (3/18/01),
Retar asked for a way to highlight the (TextBox) control when it received the focus, not to clear it (or any other) controls content. The brief little procedure I posted does exactly what I think Retar asked for. It also lets VB clear the highlight automatically when the focus leaves the control. It is -IMHO - the easiest way to do this on a more-or-orless global basis, although I would be glad to see any suggestion for an easier or more direct way to do it.


MichaelRed
redmsp@erols.com

There is never time to do it right but there is always time to do it over
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top