Disable beep of enter and escape key c#

You have to prevent the KeyPressed event from being generated, that's the one that beeps. That requires setting the SuppressKeyPress property to true. Make that look similar to:

        if ((e.KeyCode == Keys.Enter) || (e.KeyCode == Keys.Tab))
        {
            Parent.SelectNextControl(textBox_Zakljucak, true, true, true, true);
            e.Handled = e.SuppressKeyPress = true;
        }

If you want to prevent the event from bubbling up in Winforms or WPF/Silverlight, you need to set e.Handled to true from within the event handler.

Only do this if you have actually handled the event to your satisfaction and do not want any further handling of the event in question.


this works for me.

private void txtTextbox_KeyDown(object sender, KeyEventArgs e)
{
    //do somthing

    if(e.KeyCode==Keys.Enter)
    {
        e.Handled=true;
        e.SuppressKeyPress=true;
    }
}

private void txtTextbox_KeyUp(object sender, KeyEventArgs e)
{
    e.Handled=false;
    e.SuppressKeyPress=false;
}

Tags:

C#

Beep

Enter