Annoying beep when I hit enter in a textbox

Viewed 2311

I'm trying to have some stuff happen when a user presses enter in a textbox, and it works, but it makes a very annoying DING windows error sound when I do. I've looked up my problem, and apparently adding e.SuppressKeyPress = true; before the stuff, and e.Handled = true; after the stuff, but my program still makes the sound. This is the code I'm using:

private void textBox1_KeyUp(object sender, KeyEventArgs e)
{
    e.SuppressKeyPress = true;
    if (e.KeyCode == Keys.Enter)
    {
        // A bunch of stuff goes here that I want to 
        // happen when the user hits enter               
    }
    e.Handled = true;
}

Am I doing something wrong? This is what the other people said you have to do, but it's not working for me for some reason...

Thanks!

3 Answers

What you did was not wrong just put (e.supperkeypress = ture) inside if statement.

private void textBox1_KeyUp(object sender, KeyEventArgs e)
{

    if (e.KeyCode == Keys.Enter)
    {
        e.SuppressKeyPress = true;
        // A bunch of stuff goes here that I want to 
        // happen when the user hits enter               
    }
    e.Handled = true;
}
Related