如果Main窗口为MDI窗口,只需要设置属性IsMdiContainer为Ture;弹出来的窗体添加如下代码就可以让子窗口在父窗体中嵌套弹出。
private
void ShowForm1_Cick(
object sender, EventArgs e)
{
Form1 childForm = new Form1();
childForm.MdiParent = this;
{
Form1 childForm = new Form1();
childForm.MdiParent = this;
childForm.Show();
}
}
问题来了,如果在Main窗口中,添加了 splitContainer容器控件,此时就会出现子窗体不能在父窗体中显示。
解决办法:
private
void ShowForm1_Cick(
object sender, EventArgs e)
{
Form1 childForm = new Form1();
childForm.MdiParent = this;
this.splitContainer1.Panel2.Controls.Add( chi ldForm );
childForm.Show();
}
{
Form1 childForm = new Form1();
childForm.MdiParent = this;
this.splitContainer1.Panel2.Controls.Add( chi ldForm );
childForm.Show();
}