Click here to Skip to main content
15,868,016 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a mdi parent form with the tool bar. And that form contains panel that showing the company details (name, addresses,logo). I need to open a child form on this by clicking a menu item. When child form loads that panel in the main form should not visible. After closing the child form it should be displayed. On menu item clicked my code is like this,

C#
panel1.Visible = false;  
form1 frm = new form1();
            
frm.MdiParent = this;
            
frm.ShowDialog(this);
panel1.Visible = true;


But I'm getting error "Form that is not a top-level form cannot be displayed as a modal dialog box. Remove the form from any parent form before calling showDialog."
Posted

This is what it is: remove the line "frm.MdiParent = this". There is no situation when you need a form to be a MDI child and a modal dialog at the same time.

Speaking of MDI: who needs it? Don't torturing yourself and scare off your users.
See:
http://en.wikipedia.org/wiki/Multiple_document_interface#Disadvantages[^],
Question on using MDI windows in WPF[^],
MDIContainer giving error[^].

—SA
 
Share this answer
 
v2
Use this code on item clicked.
panel1.Visible = false;
form1 frm = new form1();
frm.ShowDialog();

Use the below code in MDIParent2_Activated event.
private void MDIParent_Activated(object sender, EventArgs e)
{
   panel1.Visible = true;
}
 
Share this answer
 
You can create a custom class deriving from System.Windows.Forms.Form. Pass the parent form's ref. to the constructor while creating the child form. In the constructor hide the parent form using reference. On form closing event show the parent form again using the reference.
 
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