合并工具条 MDI 子级 - 父级

发布于 2024-10-21 06:05:31 字数 569 浏览 4 评论 0原文

我在互联网上找到了一些信息,但没有任何帮助。 如何在父 MDI 表单中合并工具条?

编辑:

这段代码对我有用:

private void MainForm_MdiChildActivate(object sender, EventArgs e)
{
    IChildWindow child = ActiveMdiChild as IChildWindow;

    if (child != null)
    {
        ToolStripManager.Merge(child.ToolStrip, toolStrip1);
        child.ToolStrip.Hide();

        child.FormClosing += delegate(object sender2, FormClosingEventArgs fe)
        {
            child.ToolStrip.Show();
            ToolStripManager.RevertMerge(toolStrip1, child.ToolStrip);
        };
    }
}

I found some informations on the internet but nothing helped me out.
How can I merge a toolstrip in the parent mdi form?

Edit:

It worked for me with this code:

private void MainForm_MdiChildActivate(object sender, EventArgs e)
{
    IChildWindow child = ActiveMdiChild as IChildWindow;

    if (child != null)
    {
        ToolStripManager.Merge(child.ToolStrip, toolStrip1);
        child.ToolStrip.Hide();

        child.FormClosing += delegate(object sender2, FormClosingEventArgs fe)
        {
            child.ToolStrip.Show();
            ToolStripManager.RevertMerge(toolStrip1, child.ToolStrip);
        };
    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

小…楫夜泊 2024-10-28 06:05:31

您需要使用ToolStripManager。它有一个名为 Merge(ToolStrip, ToolStrip) 的方法,可以执行您想要的操作。
请参见此处

例如:

ToolStripManager.Merge(((YourChildForm)this.ActiveMdiChild).ToolStrip, parentFormToolStrip);

You need to use a ToolStripManager. It has a method called Merge(ToolStrip, ToolStrip) which does what you want to.
See here

For example:

ToolStripManager.Merge(((YourChildForm)this.ActiveMdiChild).ToolStrip, parentFormToolStrip);
寂寞清仓 2024-10-28 06:05:31

在子窗体中,还可以执行以下操作:

Private Sub Child_ParentChanged(sender As Object, e As System.EventArgs) Handles Me.ParentChanged
    Try
        ToolStripManager.Merge(Me.ToolStrip, TryCast(sender.mdiParent, frmMain).ToolStrip)
    Catch ex As Exception
        mErrorLog.ApplicationErrorLog(Me.GetType.Name, "frmTechSelectWO_ParentChanged", ex.ToString)
    Finally
        Me.ToolStrip.Hide()
        Me.MenuStrip1.Hide()
    End Try
End Sub


Private Sub Child_FormClosing(sender As Object, e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
    '
    ' Clean up the parent toolbar
    Try
        ToolStripManager.RevertMerge(TryCast(Me.MdiParent, frmMain).ToolStrip)
    Catch ex As Exception
    End Try
End Sub

From within the child form one can also perform the following:

Private Sub Child_ParentChanged(sender As Object, e As System.EventArgs) Handles Me.ParentChanged
    Try
        ToolStripManager.Merge(Me.ToolStrip, TryCast(sender.mdiParent, frmMain).ToolStrip)
    Catch ex As Exception
        mErrorLog.ApplicationErrorLog(Me.GetType.Name, "frmTechSelectWO_ParentChanged", ex.ToString)
    Finally
        Me.ToolStrip.Hide()
        Me.MenuStrip1.Hide()
    End Try
End Sub


Private Sub Child_FormClosing(sender As Object, e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
    '
    ' Clean up the parent toolbar
    Try
        ToolStripManager.RevertMerge(TryCast(Me.MdiParent, frmMain).ToolStrip)
    Catch ex As Exception
    End Try
End Sub
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文