To detect an ‘Enter’ key press you must understand basic terminology.
A KeyPressEventArgs specifies the character key when the user presses it. A KeyPress event occurs when the key is pressed. The KeyDown event precedes the KeyPress event. The KeyUp event occurs when the user releases the key. While a user is holding the key, duplicate KeyDown and KeyPress events occur each time the character repeats. With each KeyPress event, a KeyPressEventArgs is passed. A KeyEventArgs is passed with each KeyDown and KeyUp event. Also KeyEventArgs carries information about whether any modifier keys (CTRL, SHIFT, or ALT) were pressed along with another key.
The following example illustrates using the KeyPressEventArgs to detect and enter key press. I am using a form with a Textbox
public class theKeyPress
{
private TextBox textBox1 = new TextBox();
private void theKeyCounter(object sender, KeyPressEventArgs ar)
{
switch(ar.KeyChar)
{ case '\r': MessageBox.Show(“Enter Key Pressed!”); break ;
}
}
?>