在表单内创建表单

时间:2011-06-24 05:44:24

标签: c# visual-studio-2010

我是Visual Studio 2010的新手,我打算创建一个计时系统。我只是想问一下如何创建一个组成2个表单的表单。例如,如果我单击一个按钮,它将在表单中打开一个新表单。请帮忙。感谢

5 个答案:

答案 0 :(得分:6)

您必须与MDI (Multiple Document Interface)合作,请查看可能有帮助的article

答案 1 :(得分:6)

Form formA = new Form();
formA.IsMdiContainer = true;

Form formB = new Form();
formB.MdiParent = formA;
formB.Show();

答案 2 :(得分:3)

您可以创建自定义表单,删除所有边框和工具栏,使其尽可能贴近面板。然后将新的自定义表单作为MdiContainer / MDI面板并在该面板中显示表单,类似下面的代码将完成这项工作

Mdi-Panel definiton:

公共类MdiClientPanel:Panel {     私人表格mdiForm;     private MdiClient ctlClient = new MdiClient();

public MdiClientPanel()
{
    base.Controls.Add(this.ctlClient);
}

public Form MdiForm
{
    get
    {
        if (this.mdiForm == null)
        {
            this.mdiForm = new Form();
            /// set the hidden ctlClient field which is used to determine if the form is an MDI form
            System.Reflection.FieldInfo field = typeof(Form).GetField("ctlClient", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
            field.SetValue(this.mdiForm, this.ctlClient);
        }
        return this.mdiForm;
    }
}

}

用法:

/// mdiChildForm is the form that should be showed in the panel
/// mdiClientPanel is an instance of the MdiClientPanel
myMdiChildForm.MdiParent = mdiClientPanel1.MdiForm;

答案 3 :(得分:2)

我认为,这是一种非常简单的方式:

    Form1 form= new Form1 ();
    form.TopLevel = false;
    this.Controls.Add(form);
    form.Show();

答案 4 :(得分:1)

也许MDI界面会做你想要的......

Here's这是一个教程。