kacalapy
kacalapy

Reputation: 10154

select all text in a textarea with CTRL+A

In a winforms application, is it possible to select all text using CTRL+A?

Upvotes: 3

Views: 1373

Answers (3)

Hans Passant
Hans Passant

Reputation: 942000

Just write the KeyDown event handler for the text box:

    private void textBox1_KeyDown(object sender, KeyEventArgs e) {
        if (e.KeyData == (Keys.Control | Keys.A)) {
            textBox1.SelectAll();
            e.Handled = e.SuppressKeyPress = true;
        }
    }

UPDATE: starting with .NET 4.6.1, TextBox now has this shortcut keystroke pre-defined.

Upvotes: 8

blitz_jones
blitz_jones

Reputation: 1078

Note that Ctrl-A to select-all works out-of-the-box (by default) in the RichTextBox control.

Upvotes: 2

sino
sino

Reputation: 776

put event onkeypress and use SelectAll Method

http://msdn.microsoft.com/en-us/library/system.windows.controls.textbox.selectall%28v=vs.95%29.aspx

Upvotes: 1

Related Questions