Click here to Skip to main content
14,386,278 members
Rate this:
Please Sign up or sign in to vote.
See more:
I would like to close all opened child forms in MDI form in c#.net can anyone help
Posted
Rate this:
Please Sign up or sign in to vote.

Solution 1

Is it so difficult to look at the MSDN documentation page on a class and find the method Close?

The problem is: why MDI? How much longer people are going to get into it? Who needs MDI, ever? Why torturing yourself and scaring off your users?
Do yourself a great favor: do not use MDI at all. You can do much easier to implement design without it, with much better quality. MDI is highly discouraged even by Microsoft, in fact, Microsoft dropped it out of WPF and will hardly support it. More importantly, you will scare off all your users if you use MDI. Just don't. I can explain what to do instead.

Please see:
http://en.wikipedia.org/wiki/Multiple_document_interface#Disadvantages[^],
Question on using MDI windows in WPF[^],
MDIContainer giving error[^],
How to Create MDI Parent Window in WPF?[^].

—SA
   
Comments
VJ Reddy 13-Jun-12 13:07pm
   
Good suggestion and references. 5!
Sergey Alexandrovich Kryukov 13-Jun-12 18:25pm
   
Thank you, VJ.
--SA
Espen Harlinn 14-Jun-12 18:43pm
   
Nice reply :-D
Sergey Alexandrovich Kryukov 14-Jun-12 18:46pm
   
Thank you, Espen.
--SA
Rate this:
Please Sign up or sign in to vote.

Solution 2

// Assume that your parent window is parentForm
// When you are creating each form, add it to parentForm's owned forms
// Let's say you're creating form1
MyForm form1 = new MyForm();
parentForm.AddOwnedForm(form1);//if you're in your parentForm's class use this.AddOwnedForm(form1);
form1.Show();

// then when you want to close all of them simple call the below code

foreach(Form form in parentForm.OwnedForms)
{
      form.Close();
}

// And also you can call this if you're in parentForm's class
foreach(Form form in this.OwnedForms)
{
      form.Close();
}</pre>
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100