DEV Community

Cover image for Ctrl+A Select all text in a text box
Adam K Dean
Adam K Dean

Posted on

Ctrl+A Select all text in a text box

Another quick-snip here. Add select all (ctrl+a) to a regular textbox in less than 7 seconds, and here's how. Using the KeyDown event, look for control and A, and then select all, suppressing the keypress to stop the pingggggg noise:

private void txtInput_KeyDown(object sender, KeyEventArgs e)
{
    if (e.Control && e.KeyCode == Keys.A)
    {
        txtInput.SelectAll();
        e.Handled = true;
        e.SuppressKeyPress = true;
    }
}
Enter fullscreen mode Exit fullscreen mode

And there you have it. Enjoy

Discussion (0)