Click here to Skip to main content
15,888,454 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I am creating mdi application
in that i have some child form

my broblem is :

I open child form using menuStrip
when i open first child form(may be any form)
afterthat when i open another child form, first child form i had opened should be automatically closed.
Posted
Comments
Sergey Alexandrovich Kryukov 4-Jun-12 0:20am    
Not a question. What does that mean, "to open a form"? (Create, show, what?)
Is there any special reason to use such a bad thing as MDI?
--SA

1 solution

To do this, you need to do two things:
1) Keep a reference in your MDI parent class of what instances of each form type are open. I would probably make it an instance of the actual form:
C#
private MyMDIChild current = null;
...
if (current != null)
   {
   current.Close();
   }
current = new MyMDIChild();
current.Show();

2) Attach a handler to the child forms FormClosing event before you show it, and return "current" to null in the handler.
 
Share this answer
 

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