Mdiparent和SplitContainer

时间:2012-06-12 07:19:50

标签: c# parent-child mdichild mdiparent splitcontainer

我在MDI父表单中使用SplitContainter

我的问题是我在panel1中加载了一个名为 First Form 的表单。在带有按钮的第一个表单中,我在panel2中加载SecondForm

我正在使用此代码:

        Form In_but = new SecondForm();
        In_but.MdiParent = this.ParentForm;
        In_but.TopLevel = false;
        this.splitContainer1.Panel2.Controls.Add(In_but);
        In_but.Show();

但它不起作用。错误是:does not contain definition splitContainer1

3 个答案:

答案 0 :(得分:0)

通过查看您的代码示例,我怀疑您的问题是在您引用this.splitContainer时,this是您在面板1上的'第一个表单',而您的SplitContainer在this.ParentForm

我建议将该行更改为this.(ParentForm as <whatever class your parent form is>).splitContainer1.Panel2.Controls.Add(In_but);

答案 1 :(得分:0)

试试这个

frmChild frmChild = new frmChild();
        frmChild.TopLevel = false;
        frmChild.Parent = this.splitContainer3.Panel2;
        frmMasterlistAdministrationAdd.Show();

答案 2 :(得分:-1)

frmTest fs = new frmTest();  //frmTest is the form that you going to call 

fs.MdiParent = this; //the main form is a mdiform and have a splitcontainer with 
                     //two panels

this.splitContainer1.Panel2.Controls.Add(fs); //add the fs form to the panel2

fs.Show(); //show the form