2011-03-09 171 views
4

我在互聯網上發現了一些信息,但沒有任何幫助我。 如何合併父級mdi表單中的工具條?合併工具條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); 
     }; 
    } 
} 

回答

6

您需要使用ToolStripManager。它有一個叫做Merge(ToolStrip, ToolStrip)的方法,它可以做你想做的事。 See here

例如:

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

從子內形成一個還可以執行以下步驟:

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