If you use the event handler itself instead of a separate routine, you have access to the FormClosingEventArgs which will allow you to cancel the closing if necessary. Also you're using this.Close();
, which just restarts the event, instead of returning and letting the event finish. When I use this code set as the event handler it works on Win7 as expected:
private void Form2_FormClosing(object sender, FormClosingEventArgs e)
{
if(SpreadSheet.Changed)
{
switch(MessageBox.Show("Would you like to save your changes?", "Spreadsheet Utility",
MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning))
{
case DialogResult.Yes:
SaveFileOperation();
return;
case DialogResult.No:
return;
case DialogResult.Cancel:
e.Cancel = true;
return;
}
}
}