简体   繁体   中英

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.

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;

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 
}  

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM