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 press Ctrl-A to select all of the text in a TextBox
DescriptionThis example shows how to let the user press Ctrl-A to select all of the text in a TextBox in Visual Basic 6.
Keywordsctrl-A, control-A, select text
CategoriesStrings, Controls
 
When the TextBox's KeyPress event sees the Ctrl-A key code (1), it calls subroutine SelectAllText. That routine sets the control's SelStart property to 0 and its SelLength property to the length of the text in the control.
 
Private Sub Text2_KeyPress(KeyAscii As Integer)
Const CTRL_A As Integer = 1

    If KeyAscii = CTRL_A Then SelectAllText Text2
End Sub

Private Sub SelectAllText(ByVal txt As TextBox)
    txt.SelStart = 0
    txt.SelLength = Len(txt.Text)
End Sub
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated