[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Closing child form in MDI application

Posted on 2006-07-11
3
Medium Priority
?
688 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

What’s Wrong with Your Cloud Strategy ?

Even as many CIOs are embracing a cloud-first strategy, the reality is that moving to the cloud is a lengthy process and the end-state is likely to be a blend of multiple clouds—public and private. Learn why multicloud solutions matter in this webinar by Nimble Storage.

Question has a verified solution.

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

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
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!
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

650 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