Rabu, 13 Desember 2023

Handle Keyboard Shortcut In Microsoft Visual Basic

How to let the user press Ctrl-A to select all of the text in a TextBox in Visual Basic 6.

Method 1

Private Sub Text1_KeyPress(KeyAscii As Integer)
Const CTRL_A As Integer = 1
    If KeyAscii = CTRL_A Then SelectAllTextBox Text1
End Sub
Private Sub SelectAllTextBox(ByVal txt As TextBox)
    txt.SelStart = 0
    txt.SelLength = Len(txt.Text)
End Sub

Method 2

Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer)
If Shift = vbCtrlMask And KeyCode = vbKeyA Then
    Text1.SelStart = 0
    Text1.SelLength = Len(Text1)
End If
End Sub

Visual Basic Classic, Visual Basic 6, Programming Language

Bibliography:

https://www.petanikode.com/,https://www.codecademy.com

Related Post:

    Tidak ada komentar:

    Posting Komentar