MessageBox doesn't do anything on Application Exit

i'm not sure why this is, maybe some of you guys can help me out.

i have an MDI application.
i have a MDI child inside the parent.
i click the "X" of the MDI window to shut down the application.
i have a call to MessageBox.Show in the Dispose(bool) method of the child.

nothing shows.

i put a break point, and i can actually step through it and it hits the line where i show a message box, but it passes through it and nothing comes up.

i need this functionality because when the application closes i need to ask a question for each MDI child. it works fine if i close the child inside the MDI parent.

is there some event i can listen to or something like that the ApplicationExit event occurs too late.

thanks!


Answer this question

MessageBox doesn't do anything on Application Exit

  • Steve Hoff

    Hi,

    you can use MDI child's FormClosing event, where you can also cancel MDIParent from closing:

    private void Form2_FormClosing(object sender, FormClosingEventArgs e)
    {
    if (e.CloseReason == CloseReason.MdiFormClosing)
    {
    e.Cancel = (
    MessageBox.Show("My MDI Form is closing. Do you want to close me ", "MDI Closing", MessageBoxButtons.YesNo) == DialogResult.No);
    }
    }

    There are quite a few Closing Reasons you can react to differently...

    Andrej



  • MessageBox doesn't do anything on Application Exit