select all text in a textarea with CTRL+A

后端 未结 3 743
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-20 07:51

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

相关标签:
3条回答
  • 2021-01-20 08:26

    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.

    0 讨论(0)
  • 2021-01-20 08:26

    put event onkeypress and use SelectAll Method

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

    0 讨论(0)
  • 2021-01-20 08:40

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

    0 讨论(0)
提交回复
热议问题