- This topic explains about, how to make ctrl A to select all text in TextBox in VB programming.
Make ctrl A to select all text in VB – Working
- When the TextBox’s KeyPress event sees the Ctrl-A key code (1), it casts the event’s sender into a TextBox and calls the TextBox’s SelectAll method.
- The code then sets e.Handled to True to indicate that the character has been handled.
- This prevents the TextBox from beeping.
Control.KeyPress Event – Make ctrl A to select all text in VB
- Control.KeyPress Event occurs when a key is pressed while the control has focus.
- The KeyPress event is not raised by noncharacter keys; however, the noncharacter keys do raise the KeyDown and KeyUp events.
- Use the KeyChar property to sample keystrokes at run time and to consume or modify a subset of common keystrokes.
Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in System.Windows.Forms.dll)
- Syntax for Control.KeyPress Event
|
1 2 |
'Declaration Public Event KeyPress As KeyPressEventHandler |
DirectCast – Make ctrl A to select all text in VB
- DirectCast introduces a type conversion operation based on inheritance or implementation.
- DirectCast does not use the Visual Basic run-time helper routines for conversion, so it can provide somewhat better performance than CType when converting to and from data type Object.
- You use the DirectCast keyword the same way you use the CType Function and the TryCast keyword.
TextBoxBase.SelectAll Method – Make ctrl A to select all text in VB
- Help to select all text available in TextBox
Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in System.Windows.Forms.dll)
Make ctrl A to select all text in VB – Complete Code
|
1 2 3 4 5 6 |
Private Sub TextBox1_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress If e.KeyChar = Convert.ToChar(1) Then DirectCast(sender, TextBox).SelectAll() e.Handled = True End If End Sub |
Make ctrl A to select all text in VB
If you have any suggestion or doubts regarding this topic, please contact us…






