Form1(MDIParent)
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
public partial class Form1 : Form
{
public interface ITools
{
ToolStrip CipherToolStrip
{
get;
}
}
public Form1()
{
InitializeComponent();
}
private void newToolStripMenuItem_Click(object sender, EventArgs e)
{
Form2 f2 = new Form2();
f2.MdiParent = this;
f2.Show();
}
private void Form1_MdiChildActivate(object sender, EventArgs e)
{
ToolStripManager.RevertMerge(MDIParent);
if (this.ActiveMdiChild != null)
{
if ((ActiveMdiChild as ITools).CipherToolStrip != null)
{
ToolStripManager.Merge((ActiveMdiChild as ITools).CipherToolStrip, MDIParent);
}
}
if (MDIParent.Items.Count > 0)
MDIParent.Visible = true;
else
MDIParent.Visible = false;
}
}
Form2(MDIChild)
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
public partial class Form2 : Form, Form1.ITools
{
public ToolStrip CipherToolStrip
{
get
{
return MDIChild;
}
}
public Form2()
{
InitializeComponent();
}
private void Form2_Load(object sender, EventArgs e)
{
MDIChild.Visible = false;
ControlBox = false;
}
}
通过设置 MergeAction 和 MergeIndex 可以修改合并的方式与位置。
运行结果如下: