Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
MSDN Visual Basic Community
 
 
 
 
 
TitleLet the user select all text with Ctrl-A in all TextBoxes
Keywordstextbox, ctrl-a, control-a, select all
CategoriesControls
 
Set KeyPreview = True. Then in the form's KeyPress event handler, check for the Ctrl-A key combination. If the user presses Ctrl-A, see if the active control is a TextBox. If it is, use its SelStart and SelLength properties to select all of its text.
 
Private Sub Form_Load()
    KeyPreview = True
End Sub

Private Sub Form_KeyPress(KeyAscii As Integer)
Const ASC_CTRL_A As Integer = 1

Dim txt As TextBox

    ' See if this is Ctrl-A.
    If KeyAscii = ASC_CTRL_A Then
        ' The user is pressing Ctrl-A. See if the
        ' active control is a TextBox.
        If TypeOf ActiveControl Is TextBox Then
            ' Select the text in this control.
            Set txt = ActiveControl
            txt.SelStart = 0
            txt.SelLength = Len(txt.Text)
        End If
    End If
End Sub
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated