I am developing a MDI application with a couple of child windows inside the Parent window (frmMain). Each project consists of 2 child windows (frmData and frmPlot).
I have a Main Menu which is used to create new Project / open new Project.
I want only one Project at a given instant. So when I click on New project menu item (mnuNew_click event) it should close the already open child windows before creating a new project. I tried to use following code but it does not close any child forms. Has someone dealt with similar problem
I am using Visual C++ .Net 2003 on Win XP
--
private: System::Void mnuNew_Click(System::Object * sender, System::EventArgs * e)
{
frmPlot * plt = new frmPlot();
plt->Close();
frmData * dat = new frmData();
dat->Close();
frmNew * frmNew = new frmNew();
frmNew->ShowDialog(this);
}
Any pointers would be very helpful
thanks
Suneet

MDI Parent and Child form - Close Child
gareon
Hadas Rodal
jamesb
What you are doing there is creating new forms and then closing them, not closing the existing ones:
I'd do something like this (it's C# but hopefully you'll get the idea):
private void mnuNew_Click(object sender, EventArgs e){
// Close all children
foreach(Form childForm in this.MdiChildren)
childForm.Close();
// Create new forms and set them as MDI child
frmPlot form1 = new frmPlot();
form1.MdiParent = this;
form1.Visible = true;
I hope this helps!
Luis Alonso Ramos