Not able to capture Enter key in WinForms text box
        Posted  
        
            by Michael Hermes
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Michael Hermes
        
        
        
        Published on 2009-11-28T00:36:56Z
        Indexed on 
            2010/05/07
            23:18 UTC
        
        
        Read the original article
        Hit count: 466
        
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();
    }
}
        © Stack Overflow or respective owner