简体   繁体   English

如何将form2的mdiParent设置为form1 c#winforms

[英]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'. 我正在使用两种形式,一种称为“Form1”的主体形式和一种名为“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. 我正在使用Windows,C#和WinForms。

Make sure that Form2 has the property IsMdiContainer set to true. 确保Form2的属性IsMdiContainer设置为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 : 然后,要将调用者Form定义为Form2的父级,请使用this (Form1的当前实例)而不是表单类的名称:

Form2.mdIparent = this;

Try this: 尝试这个:

from Form1 来自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 
}  

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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