Hi i will describe my problem.
When focus is on TextBox and we press ENTER or ESC then we will hear that sound. I'm trying to disable that. Did any one got that problem before ? I was trying to create my own SilentTextBox which will inherit from TextBox and disable that sound by overriding OnKeyPress. OnKeyDown, OnKeyUp and OnPreviewKeyDown.

For example

protected override void OnKeyPress(KeyPressEventArgs e)
        {
            if ((e.KeyChar != 13) || (e.KeyChar != 27))
            {
                base.OnKeyPress(e);
            }
        }

Unfortunately that doesn't disable that ping sound.
thx in advance for any help.

You must not use base.OnKeyPress(e); in your override. By doing so, you will first execute what is already programmed in the base class, which is a behaviour you don't want.

You can't disable it. "you can't" == you can but after huge efforts. what does this sound means to you?! it means you haven't accept button on your forum, once you've this button you won't get this sound + TextBox class not getting this sound itself, but OS does.

Thank you for reply. I decided to use combination of label and button works actually better now.

Your solution is correct, except that you should use

(e.KeyChar != 13) && (e.KeyChar != 27)

because by using OR, when it's ENTER, it's not ESC, and the default handler is called (and vice-versa).

// Stop the annoying BEEP when user presses ENTER or ESCAPE...
        protected override void OnKeyPress(KeyPressEventArgs e) 
        {
            if (e.KeyChar == (char)Keys.Enter || e.KeyChar == (char)Keys.Escape)
            {
                e.Handled = true;   // stop annoying beep
            }
            
            // call base handler...
            base.OnKeyPress(e);
        }

Edited 7 Years Ago by DdoubleD: n/a

This question has already been answered. Start a new discussion instead.