Not able to capture Enter key in WinForms text box

c#, visual-studio-2008, winforms

Solution

Are you sure the click on the button isn't performed ? I just did a test, it works fine for me. And here's the way to prevent the "ding" sound :

private void tbxMod_KeyDown(object sender, KeyEventArgs e)
{
    if (e.KeyCode == Keys.Enter)
    {
        btnMod.PerformClick();
        e.SuppressKeyPress = true;
    }
}

Problem

When the user is entering a number into a text box, I would like them to be able to press Enter and simulate pressing an Update button elsewhere on the form. I have looked this up several places online, and this seems to be the code I want, but it's not working. When data has been put in the text box and Enter is pressed, all I get is a ding. What am I doing wrong? (Visual Studio 2008) ``` private void tbxMod_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { btnMod.PerformClick(); } } ```

Original source