?
Solved

Closing child form in MDI application

Posted on 2006-07-11
3
Medium Priority
?
685 Views
Last Modified: 2012-05-05
Hi all,

I have a MDI application, in child form class I write event handler to handle FormClosing event. In the event handler I show a message box to ask user to save their changes to the document. I write code to do the task as follow. If user selects Yes the document will be save and the form will be closed, if user selects No then form will be close without saving document, and if user select Cancel the Cancel property of FormClosingEventArgs will be set to true and do nothing. But when I run my application, when message is promted I select No in some form and select Cancel at the message of last form. If it is correct then there is one child form in my application but in my application, all child form still remaining and not closed.

Please tell me why and let me know the way to solve this problem.
thanks and best regard.
0
Comment
Question by:ncsvietnam
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 2

Accepted Solution

by:
Anandavally_P earned 500 total points
ID: 17089304
Try this,

This is the closing event of the child form.

 private void Form2_FormClosing(object sender, FormClosingEventArgs e)
 {
      DialogResult result = MessageBox.Show(this, "Do you want to close", "Confirm",
                                                                 MessageBoxButtons.YesNoCancel);
      // If the result is yes then save the form and the form is closed
       if (result == DialogResult.Yes)
       {
            MessageBox.Show("save the form");                
       }
       // If the result is no dont save the form and the form is closed
       else if (result == DialogResult.No)
       {
            MessageBox.Show("Do not save the form");                
       }
      // If the result is cancel then set the argument to cancel value to true
       else if (result == DialogResult.Cancel)
       {
            e.Cancel = true;
        }                  
 }

I think you would have called the function this.Close() after saving the form. It will again call the form closing event and eventually you will end up in keeping the form open.

Regards,
Anandavally P
0

Featured Post

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question