开发者

Merge toolstrip MDI child - parent

开发者 https://www.devze.com 2023-02-16 00:47 出处:网络
I found some informations on the internet but nothing helped me out. How can I merge a toolstrip in the parent mdi form?

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);
        };
    }
}


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);


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
0

精彩评论

暂无评论...
验证码 换一张
取 消