你好,
首先, 确认Form1 的 IsMdiContainer 设置为 true.
然后初始化 Form1 和Form2, 设置Form1 作为 Form2's MdiParent:
// Form1.IsMdiContainer should be true
Form1 form1 = new Form1();
// This automatically adds form2 into form1's MdiChildren collection
Form2 form2 = new Form2();
form2.MdiParent = form1;
在 Form2 的代码,你可以参考一下下面的代码。
public class Form2 : Form {
// Include as data member so we only instantiate one Form3
Form3 _form3;
public Form2() {
InitializeComponent();
Button1.Click += new EventHandler(Button1_Click);
}
private void Button1_Click(object sender, EventArgs e) {
if(_form3 == null) {
_form3 = new Form3();
// Set Form3's parent to be Form1
_form3.MdiParent = this.MdiParent;
}
}
}
Best regards,
Zhanglong
MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to
MSDN Support, feel free to contact MSDNFSF@microsoft.com.