I am trying to close my application when closing the menu form.
This is my code:
private void frmMenu_FormClosing(object sender, FormClosingEventArgs e)
{
var result = MessageBox.Show("Do you want to close this application",
"Alert", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
if (result == DialogResult.Yes)
{
//this.Close();
Application.Exit();
//e.Cancel = false;
}
else
{
e.Cancel = true;
}
}
When closing this message appears twice.
You can override the
OnFormClosingmethod:Or following Hans Passant‘s advice in the comments on using a bool (e.g.
IsDataValid) in your class: