You have to do it like this:
private void FormA_FormClosing(object sender, FormClosingEventArgs e)
{
DialogResult closing = MessageBox.Show("Are you sure you want to exit the game?", "EXIT", MessageBoxButtons.YesNo);
if (closing == DialogResult.No)
{
e.Cancel = true;
}
}
Your code didn't work because when you clicked No, nothing would cancel the closing.
[Edit]
If you want that the application exits when your form (which is not the main form) closes, then you have to exit the application after the child form is closed:
ChildForm childFrm = new ChildForm();
childFrm.FormClosed += childFrm_FormClosed;
private void childFrm_FormClosed(Object sender, FormClosedEventArgs e)
{
Application.Exit();
}
Note that you have to add the
childFrm_FormClosed
in the class of the form that creates your child form. You also don't have to do this for every child form, only this one.