Solved

Closing child form in MDI application

Posted on 2006-07-11
3
680 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 125 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
ASP.NET - Why is accordion not working? 3 70
orderby list (from Json) 1 43
asp.net repeater 2 35
Windows Universal App 22 58
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…
Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

734 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