FormClosing Event And Cancelling The Close

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

In a WinForm, in the FormClosing event, there is an opportunity to cancel the
close by setting the Cancel property of the FormClosingEventArgs to true.
This is typically done when there is unsaved data on the form and the user,
when asked if they want to close the form and lose data or not, says not to
close.

Our app is a MDI type that holds several windows. When the app gets closed,
each form in it gets closed, getting their FormClosing event, then the
mainframe form gets its FormClosing event. Problem I have is that the
mainframe needs to know if any of the forms in it canceled their close
(because of the above) and if they did the mainframe will cancel the app
closing. But how can the main form, in his FormClosing event, know that? Is
there a way?

Thanks
Rich Sienkiewicz
DragonPoint Software
(e-mail address removed)
 
Never mind I found out how to do it. In the mainframe's FormClosing event the
Cancel property will set to true if any mdi child canceled his close. In that
case do a return:

private void Frame_FormClosing(object sender, FormClosingEventArgs e)
{
if (e.Cancel == true)
return;
}

Rich Sienkiewicz
DragonPoint Software
(e-mail address removed)
 
Actually I had to do nothing, like the below, I just had to ensure that the
mdi children canceled their close.

Rich
 
Back
Top