Sep 10
9
How to suppress “beep” when pressing enter
Leave a comment »
I’m sitting here writing a chat application and needed a way to suppress the beep sound when the enter key was pressed on my text entry box. It’s a single-line Rich Text control and I had thought it was just a matter of setting KeyChar to 0 on the key press event. In fact, this is exactly what Microsoft recommends here http://support.microsoft.com/default.aspx?scid=kb;en-us;Q140882
But I found this not to work for the richtext control. In fact, I had to trap this key in the KeyDown event rather than the KeyPress event. Just an FYI in case you’re attempting to do the same, and expect Microsoft to have the solution.
Instead, we set SuppressKeyPress = true; and the beep will go away!
private void RichEditor_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { e.SuppressKeyPress = true; // do something else if needed } }
