Click here to Skip to main content
15,891,529 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I've 2 forms named as 'mdfi' & 'form1',i want to make 'mdfi' form as MdiContainer by code from 'form1' i tried a lot do with this code but the programs close when i run. Here the code am trying

private void Form1_Deactivate(object sender, EventArgs e)
{
this.TopMost = false;
Mdfi newMDIChild = new Mdfi();
newMDIChild.IsMdiContainer = true;
this.MdiParent = newMDIChild;
newMDIChild.Show();
Posted

1 solution

You can't make the parent form from a child form the parent need to come before the child. Use this instead.

C#
private void buttonFormActivator_Click(object sender, EventArgs e)
{
    //Create parent and child forms    
    Form MyMdiParentForm = new Form();
    Form MyNewMdiChildForm = new Form();

    //Make Parent form an MDI container
    MyMdiParentForm.IsMdiContainer = true;
    // Set the Parent Form as the parent of the Child Form.
    MyNewMdiChildForm.MdiParent = MyMdiParentForm;
    //Display the Parent form
    MyMdiParentForm.Show();
    // Display the child form.
    MyNewMdiChildForm.Show();

    // Hide your initial form, 
    // take care to write a method
    // to close this form when you are
    // done with the application. (Like a while app active loop)
    this.Hide();
}
 
Share this answer
 

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


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