从子表单向splitcontainer添加表单

时间:2015-12-23 22:58:45

标签: c# winforms mdi mdichild

我正在尝试从子表单中向SplitContainer添加表单。我可以使用此表单从父表单中执行此操作。

Lockdown.MainForm form = new Lockdown.MainForm(true);
form.MdiParent = this;
form.TopLevel = false;
form.Dock = DockStyle.Fill;
this.splitContainer.Panel2.Controls.Add(form);
form.Show();

但我无法弄清楚如何从父表格的孩子那里做到这一点。 任何帮助表示赞赏。

1 个答案:

答案 0 :(得分:0)

以下是我解决问题的方法。我通过了对子表单的引用。

        MessageBoxRegister register = new MessageBoxRegister(this);
        register.ShowDialog();

然后我将引用保存在全局变量中。

    Launcher launcher;
    public MessageBoxRegister(Launcher launcher)
    {
        InitializeComponent();

        this.launcher = launcher;
    }

然后我可以将表单打开到splitContainer中。

            Lockdown.MainForm form = new Lockdown.MainForm(true);
            form.MdiParent = launcher;
            form.TopLevel = false;
            form.Dock = DockStyle.Fill;
            launcher.splitContainer.Panel2.Controls.Add(form);
            form.Show();
相关问题