Here is one more way to handle the enter key and any other key.
For this example I have one button on a form. The onclick event of the button is as follows:
private void btnClickMe_Click(object sender, System.EventArgs e)
{
MessageBox.Show("Hello World!");
}
This just displays a message box when the user clicks the button.
Now select the form and add this to the KeyUp event:
private void Form1_KeyUp(object sender, System.Windows.Forms.KeyEventArgs e)
{
if(e.KeyCode == Keys.Enter)
{
this.btnClickMe_Click(new System.Object(), System.EventArgs.Empty);
}
}
Simple right? You can call any key that you would like here. Just replace Keys.Enter with whatever key you would like. Basically what happens is when the user presses the enter key, it calls btnClickMe's click event and passes a blank object and empty args. You can use this to fire an event from anywhere.