WinForms does not automatically enable Ctrl-A as “Select All” action.
The below code snippet works when you bind it to the KeyDown event of a TextBox (actually the event is on Control).
The e.SuppressKeyPress = true
suppresses the bell sound in a multiline TextBox, as e.Handled = true
won’t.
private void textBox_KeyDown_HandleCtrlAToSelectAllText(object sender, KeyEventArgs e) { TextBox textBox = sender as TextBox; if (null != textBox) { if (e.Control && e.KeyCode == Keys.A) { textBox.SelectAll(); e.SuppressKeyPress = true; } } }
–jeroen