玄铁剑

成功的途径:抄,创造,研究,发明...
posts - 128, comments - 42, trackbacks - 0, articles - 174

MDI窗体的工具栏合并(ToolStrip Merging)

Posted on 2007-08-01 21:41 玄铁剑 阅读(1924) 评论(0)  编辑 收藏 引用 所属分类: C# Winform

在MDI窗体定义

        public interface ICipherInputForm
        {
            ToolStrip CipherToolStrip
            {
                get;
            }
        }

在MdiChildActivate事件中加入

         private void MainFrame_MdiChildActivate(object sender, EventArgs e)
        {

//CTools为MDI窗体工具栏
            ToolStripManager.RevertMerge(CTools);
            if (this.ActiveMdiChild != null)
            {
                if ((ActiveMdiChild as ICipherInputForm).CipherToolStrip != null)
                {
                    ToolStripManager.Merge((ActiveMdiChild as ICipherInputForm).CipherToolStrip,CTools);
                }
            }
            //若子窗体无工具栏时,隐藏该工具栏
            if (CTools.Items.Count > 0)
                CTools.Visible = true;
            else
                CTools.Visible = false;
         }

在子窗体

    public partial class FrmPowerTeam : Form,MainFrame.ICipherInputForm
    {

//Tools为你子窗体的工具栏.注意将其Visible = false;
        public ToolStrip CipherToolStrip
        {
            get
            {
                return Tools;
            }
        }
   }

只有注册用户登录后才能发表评论。