0

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.

Creesch
  • 31
  • 7
  • 1
    `But that didn't work.` what exactly happened? How are you setting `mdiParent` for the first time? `Form` has `IsMdiContainer` property set to true? – Chetan Mar 21 '19 at 11:30
  • `Form2` is called from `Form1` ? – Cid Mar 21 '19 at 11:31

2 Answers2

0

Make sure that Form2 has the property IsMdiContainer set to true.

Then, to define the caller Form being the parent of Form2, use this (the current instance of Form1) instead of the name of the form class :

Form2.mdIparent = this;
Cid
  • 14,968
  • 4
  • 30
  • 45
0

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 
}  
Ruben Martirosyan
  • 870
  • 1
  • 12
  • 23