News:

Choose a design and let our professionals help you build a successful website   - ITAcumens

Main Menu

Let the user press Ctrl-A to select all of the text in a TextBox

Started by nandagopal, Nov 06, 2008, 04:08 PM

Previous topic - Next topic

nandagopal

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