合并子窗体上的菜单和工具栏的简单方法
假设主窗体上有工具栏toolStrip1,和菜单栏存在private void Form1_MdiChildActivate(object sender, EventArgs e)
{
ToolStripManager.RevertMerge(toolStrip1);
if (this.ActiveMdiChild == null) return;
foreach (Control control in this.ActiveMdiChild.Controls)
{
if (control is ToolStrip)
{
ToolStripManager.Merge((ToolStrip)control, toolStrip1);
control.Visible = false;
}
else if(control is MenuStrip )
{
control.Visible = false;
}
}
if (toolStrip1.Items.Count > 0)
{ toolStrip1.Visible = true; }
else
{ toolStrip1.Visible = false; }
}