heyu52 发表于 2008-5-29 23:14

合并子窗体上的菜单和工具栏的简单方法

假设主窗体上有工具栏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; }
        }

guang 发表于 2008-6-6 15:44

顶!!

页: [1]

编程论坛