Sunday, 6 June 2010

One-liners: Prevent beep after pressing 'enter' in a control

If you're a fan of your keyboard shortcuts, you might notice that windows sometimes emits a beep (or bell) after pressing enter to select something. Prevent the bell by setting the KeyDown eventargs SuppressKeyPress member to 'true' if the enter key was pressed.

protected override void OnKeyDown(KeyEventArgs e)
if (e.KeyCode == Keys.Enter)
e.SuppressKeyPress = true; // stop the bell!!!

No comments: