In the KeyDown event handler code, use the following:
private void Text1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
this.Close();
}
If you have a button on the form with DialogResult property set to OK, closing the form will be equal to clicking that button.
However, in this case, a simpler solution is to set the form's AcceptButton property to the name of your OK button. This will have the same effect.
However, in this case, a simpler solution is to set the form's AcceptButton property to the name of your OK button. This will have the same effect.