Click here to Skip to main content
15,884,388 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello sir,

Today, i have create one MDI parent and many child form. I want to close all child form when one child form is running.another all child form is automatically close when any one child form open. Running form should not be closed. only closed another forms if active..

Give me code for this mater.

solve this problems...

Thanking you.......
Posted

Pass the active form object to the below method it will close all the other form except the active form.
C#
public void DisposeAllButThis(Form form)
{
    foreach (Form frm in this.MdiChildren)
    {
        if (frm.GetType() == form.GetType()
            && frm != form)
        {
            frm.Close();
        }
    }
}


Hope this helps
 
Share this answer
 
Comments
keyur_raval 10-Jul-13 6:01am    
Is that class create in mdi parent form?????? or where????
C#
public void CloseAllForms(Form form)
{
    foreach (Form frm in this.MdiChildren)
    {
        if (frm.GetType() == form.GetType() && frm != form)
        {
            frm.Close();
        }
    }
}
 
Share this answer
 
if the call for opening child form is initiating from MDI form the you could easily do this my first closing all child forms and then call to opening the new child form,

"NewChild" as new form to be opened

event to open new child form

For Each ChildForm As Form In Me.MdiChildren
ChildForm.Close()
Next
NewChild.show

Easy solution, if you don't need something typical.
 
Share this answer
 
v3

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900