Visual Basic Programming Code Examples
Visual Basic > ActiveX Controls Code Examples
Highlight all text in textbox
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
Highlight all text in textbox
'Here is the main function that controls
'the highlighting of all text in a textbox.
'Additional commands can be added to this function
'to perform any other functions during a gotfocus
'event.
Public Function txtGotFocus()
Dim obj
Set obj = Form1.ActiveControl
If TypeOf obj is TextBox Then
obj.SelStart = 0
obj.SelLength = Len(obj.Text)
End if
End Function
'Here is an example of how to reference the
'function in a textbox GotFocus() event.
Private Sub Text1_GotFocus()
txtGotFocus
End Sub