in your form constructor class (formname.designer.cs) add this:
this.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.Login_KeyPress);
and add this code to the base code (formname.cs):
void Login_KeyPress(object sender, KeyPressEventArgs e) { if (e.KeyChar == (char)13) MessageBox.Show("ENTER has been pressed!"); else if (e.KeyChar == (char)27) this.Close(); }
Maziar Aboualizadeh Behbahani
source share