protected override void OnMdiChildActivate(EventArgs e)
{
base.OnMdiChildActivate(e);
#region 先撤消所有的合并项
menuStrip.SuspendLayout();
ToolStripManager.RevertMerge(menuStrip);
menuStrip.ResumeLayout(false);
menuStrip.PerformLayout();
toolStrip.SuspendLayout();
ToolStripManager.RevertMerge(toolStrip);
toolStrip.ResumeLayout(false);
toolStrip.PerformLayout();
statusStrip.SuspendLayout();
ToolStripManager.RevertMerge(statusStrip);
statusStrip.ResumeLayout(false);
statusStrip.PerformLayout();
#endregion
#region 合并菜单栏,工具栏,状态栏
Form form = this.ActiveMdiChild;
if (form != null)
{
foreach (Control control in form.Controls)
{
//以下两种情况不可以互换位置,因为StatusStrip继承于ToolStrip
if (control is MenuStrip)
{
menuStrip.SuspendLayout();
ToolStripManager.Merge((MenuStrip)control, menuStrip);
menuStrip.ResumeLayout(false);
menuStrip.PerformLayout();
}
else if (control is StatusStrip)
{
statusStrip.SuspendLayout();
ToolStripManager.Merge(((StatusStrip)control), statusStrip);
statusStrip.ResumeLayout(false);
statusStrip.PerformLayout();
control.Visible = false;
}
else if (control is ToolStrip)
{
((ToolStrip)control).SuspendLayout();
ToolStripManager.Merge(((ToolStrip)control), this.toolStrip);
((ToolStrip)control).ResumeLayout(false);
((ToolStrip)control).PerformLayout();
control.Visible = false;
}
}
}
#endregion
}