如何在选项卡式MDIChild表单中解决此问题?

时间:2011-08-18 08:10:50

标签: c#

这是什么错误: 指定为此表单的MdiParent的表单不是MdiContainer。 参数名称:值

这是代码  公共部分类Form5:表格     {         公共Form5()         {             的InitializeComponent();         }

    private void Form1_MdiChildActivate(object sender, EventArgs e)
    {
        if (this.ActiveMdiChild == null)
            tabForms.Visible = false; // If no any child form, hide tabControl
        else
        {
            this.ActiveMdiChild.WindowState = FormWindowState.Maximized; // Child form always maximized

            // If child form is new and no has tabPage, create new tabPage
            if (this.ActiveMdiChild.Tag == null)
            {
                // Add a tabPage to tabControl with child form caption
                TabPage tp = new TabPage(this.ActiveMdiChild.Text);
                tp.Tag = this.ActiveMdiChild;
                tp.Parent = tabForms;
                tabForms.SelectedTab = tp;

                this.ActiveMdiChild.Tag = tp;
                this.ActiveMdiChild.FormClosed += new FormClosedEventHandler(ActiveMdiChild_FormClosed);
            }

            if (!tabForms.Visible) tabForms.Visible = true;
        }
    }

    // If child form closed, remove tabPage
    private void ActiveMdiChild_FormClosed(object sender, FormClosedEventArgs e)
    {
        ((sender as Form).Tag as TabPage).Dispose();
    }

    private void tabForms_SelectedIndexChanged(object sender, EventArgs e)
    {
        if ((tabForms.SelectedTab != null) && (tabForms.SelectedTab.Tag != null))
            (tabForms.SelectedTab.Tag as Form).Select();
    }


    private void projectsToolStripMenuItem_Click(object sender, EventArgs e)
    {
        Form7 f7 = new Form7();

        f7.MdiParent = this;
        f7.Show();
    }


}

1 个答案:

答案 0 :(得分:1)

问题可能出在您的Form5课程中,您没有指定FormMdiContainer

尝试将IsMdiContainer属性设置为true,或在构造函数中调用InitializeComponent后手动设置属性。