Search code examples
c#formswinformsmdiparent

How to set form2's mdiParent to form1 c# winforms


I'm using two forms one mainform called 'Form1' and a seperate form called 'Form2'. So want to achieve something like that:

Form2.mdIparent = Form1;

But that didn't work. Can somebody help me ? I'm using Windows, C# and WinForms.


Solution

  • Try this:

    from Form1

    protected void Button_Click(object sender, System.EventArgs e){  
       Form2 newMDIChild = new Form2();  
    
       newMDIChild.MdiParent = this; //where this means Form1
    
       newMDIChild.Show(); //if need to open Form2 
    }