How can I disable beep sound in KeyDown event?
I already tried using "e.Handler = true" but it doesn't seem to work. I have used it sucessfuly with KeyPress events, but now with KeyDown I can't get it work...

This is my code:

private void msg_textbox_KeyDown(object sender, KeyEventArgs e)


                case Keys.Return:
                    e.Handled = true;

                case Keys.Up:
                    msg_textbox.Text = history.Up();
                    e.Handled = true;

                case Keys.Down:
                    msg_textbox.Text = history.Down();
                    e.Handled = true;



Thanks in advance for you attention.

Recommended Answers

All 3 Replies

I think you just need the SuppressKeyPress member of the EventArgs, so simply placing e.SuppressKeyPress = true; on line 3 should work.

Thanks for the response jonsca!

That doesn't solves the problem because this event is "fired" in a textbox. So, I need to enter text, I can't supress keypress.

I found a solution. I created a KeyPress handler and, when the carriage return is pressed I make "e.Handled = true;"

I thought that could be done without KeyPress event handler, just with KeyDown event handler, but i didn't find a way to acomplish that, so... that's the solution I've found!

So, I need to enter text, I can't supress keypress.

Ah, I misread the documentation. I thought it meant it wouldn't send the keypress event to the level of the OS. Apologies. Glad you got it working though!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.