Click here to Skip to main content
16,018,802 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello,

i have a MDI parent form and inside that i have menu bar for opening child forms.
when i open a child form it opens inside MDI parent form.
and when i open second child form the previous one is not closing.

the opened child form should be closed when i open new child form.....

how can i achieve this...

please help......
Posted
Comments
StM0n 11-Aug-11 6:31am    
so... only one (specific?) child is allowed to be shown? Do I get that right...?
yogesh89 16-Aug-11 6:15am    
yes you are right.....
StM0n 16-Aug-11 6:51am    
Ok... my guess would be, that you have (hopefully) plenty solutions to choose from :)
nagendrathecoder 11-Aug-11 7:14am    
Please mention do you want only one instance of a particulat child form open or you want only and only one instance of any of the child form open at a time.

You have to write code for that.

Check whether MDI has child form or not using this.HasChildren and close that instance of form using childForm.Close().
 
Share this answer
 
Comments
Pravin Patil, Mumbai 11-Aug-11 6:41am    
Very nice answer....
my 5
RaviRanjanKr 11-Aug-11 9:04am    
Nice Answer, My 5+
When opening a form use from1.ShowDialog() instead of form1.Show(). So, this will not allow you to open other without closing the current from.
 
Share this answer
 
Comments
Pravin Patil, Mumbai 11-Aug-11 6:42am    
But it will also prevent clicking on the menu bar or toolbar as long as current form is open.....
Toniyo Jackson 11-Aug-11 6:44am    
Yup. This is what OP needs
i guess you wanted that only one instance of a particular child form should be open at a time.
For this, you need to check if the instance of that child form is null then only open new instance OR otherwise if instance is already created just bring to front that instance.
 
Share this answer
 
C#
private WhatEverClassThisMayBe _TheOneAndOnlyChild;

public|private void showChild() {

    if (this._TheOneAndOnlyChild != null) {
        this._TheOneAndOnlyChild.Close();
    }

    this._TheOneAndOnlyChild = new WhatEverClassThisMayBe();

    this._TheOneAndOnlyChild.Show();

}


Something like that, would be my guess...
 
Share this answer
 
Comments
nagendrathecoder 11-Aug-11 9:00am    
If OP really wants this.....i can't imagine why he needs something like this.
Anyhow it is good answer
StM0n 11-Aug-11 9:04am    
Thanks for the reply... and honestly, I either didn't figure it out, what the OP's trying to achieve... ;)

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