Stop the Bell on CTRL-A (WinForms)

后端 未结 4 1326
野性不改
野性不改 2021-01-17 10:59

Any ideas how to stop the system bell from sounding when CTRL-A is used to select text in a Winforms application?

Here\'s the problem. Create a

4条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-17 11:33

    @H7O solution is good, but I improved it a bit for multiply TextBox components on the form.

    private void textBox_KeyDown(object sender, KeyEventArgs e)
    {
      if (e.Control && e.KeyCode == Keys.A)
      {
        ((TextBox)sender).SelectAll();
        e.SuppressKeyPress = true;
      }
    }
    

提交回复
热议问题