DEV Community

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

Posted on

2

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

Top comments (0)

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay