Detect Enter Key C#
in your form designer class (formname.designer.cs) add this :
this.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.Login_KeyPress);
and add this code to backbone 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();
}
This is because when you press Enter TextChanged
event won't fire.