David

David

  • NA
  • 1
  • 0

MDI and CHILDS form problem

May 8 2007 7:13 PM
Hi,

My English is not native, sorry.

I have MDI form and Child form.
I added "Form_Closing" event to the MDI code file. the following is the code:

private void frmMainMdi_FormClosing(object sender, FormClosingEventArgs e)
        {
            // Hold the MessageBox button pressed
            DialogResult diaResult;
            // Show Message to the User
            diaResult = MessageBox.Show("Are you sure you want to cancel the setup?",
                                        "Exit Setup",
                                        MessageBoxButtons.YesNo,
                                        MessageBoxIcon.Warning,
                                        MessageBoxDefaultButton.Button2);
           // Checking which button as been pressed
           if (diaResult == DialogResult.No)
           {
               // CANCEL pressed, set focus to the program
               e.Cancel = true;
           }
           else
           {
               // YES pressed, exit the program
               this.Dispose();
               Application.Exit();
           }
        }

Now, in the child form i have CANCEL button that suppose to teminate the application if the user press YES.

I added to the click event the following code:
private void btnCancel_Click(object sender, EventArgs e)
        {
          Application.Exit();
        }
And now I am having the problem.

I am getting an error when I try to cancel the program and the error points to the cancel button, application.exit();

How can I terminate the program from runnning when pressing the cancel button?

Thanks
VBDC