Skip to content

Instantly share code, notes, and snippets.

@PyramisDev
Created July 30, 2013 14:13
Show Gist options
  • Save PyramisDev/6113260 to your computer and use it in GitHub Desktop.
Save PyramisDev/6113260 to your computer and use it in GitHub Desktop.
Let the user press Ctrl-A to select all of the text in a TextBox in VB .NET 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.
If e.KeyChar = Convert.ToChar(1) Then
DirectCast(sender, TextBox).SelectAll()
e.Handled = True
End If
@vrdriver
Copy link

Thanks for the hint. Here's the code for Vb.NET 2017+:

If e.KeyChar = Convert.ToChar(1) Then
      TextBoxOmnyStatusOutput.SelectAll()
      e.Handled = True
End If

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment