private void WmClose (ref Message m)
{
if (this.Enabled == false)
return; // prevent closing a disabled form.
Form act = Form.ActiveForm;
// Don't close this form if there's another modal form visible.
if (act != null && act != this && act.Modal == true) {
// Check if any of the parents up the tree is the modal form,
// in which case we can still close this form.
Control current = this;
while (current != null && current.Parent != act) {
current = current.Parent;
}
if (current == null || current.Parent != act) {
return;
}
}
bool mdi_cancel = false;
// Give any MDI children the opportunity to cancel the close
if (mdi_container != null)
foreach (Form mdi_child in mdi_container.MdiChildren)
mdi_cancel = mdi_child.FireClosingEvents (CloseReason.MdiFormClosing, mdi_cancel);
bool validate_cancel = false;
if (!suppress_closing_events)
validate_cancel = !ValidateChildren ();
if (suppress_closing_events ||
!RaiseCloseEvents (false, validate_cancel || mdi_cancel)) {
if (is_modal) {
Hide ();
} else {
Dispose ();
if (act != null && act != this)
act.SelectActiveControl ();
}
mdi_parent = null;
} else {
if (is_modal) {
DialogResult = DialogResult.None;
}
closing = false;
}
}