How can I make the user able to close the about box with 'Esc' button?

The title says it!

TIA.



Answer this question

How can I make the user able to close the about box with 'Esc' button?

  • Uri Kluk

    private void AboutForm_KeyDown(object sender, KeyEventArgs e)
    {
    if (e.KeyData.ToString() == Keys.Escape.ToString())
    this.Close();
    }


  • myso

    Set, if needed, the Form.KeyPreview to true to receive the KeyPress, KeyDown, and KeyUp events even if the current form isn't selected.


    private void MyForm_KeyPress(object sender, KeyPressEventArgs e)
    {
    if( e.KeyChar == (char)Keys.Escape )
    {
    this.Close();
    }
    }



  • A Chapman

    You just need to set the About box form's CancelButton property to the OK button.

    No need to handle KeyPress, KeyDown or KeyUp events.


  • How can I make the user able to close the about box with 'Esc' button?