Re: Merge MDI child toolstrip button(s) into parent toolstrip

Holly Styles <[email protected]> Mon, 5 Nov 2007 06:56:52 -0500
Newsgroups gmane.comp.windows.devel.dotnet.winforms
Message-ID <LISTSERV%[email protected]>
Ok. I have created an interface IToolStripHost that implements
AppendToolStrip and RemoveToolStrip methods with a ToolStrip parameter for
the source ToolStrip to be appended / removed. I have a Form with
MDIContainer set to true that has a ToolStripPanel and a ToolStrip docked
within it (Apparently ToolStripContainer doesn't play well in an MDI type
App) You have to add ToolStripPanel to your toolbox as it's not there by
default.

The MDI Parent form implements IToolStripHost and uses the static
ToolStripManager instance to Merge /RevertMerge source ToolStrips.

        public bool AppendToolStrip(ToolStrip sourceToolStrip)
        {
            return ToolStripManager.Merge(sourceToolStrip, this.toolStrip1);
        }

        public bool RemoveToolStrip(ToolStrip toolStrip)
        {
            return ToolStripManager.RevertMerge(this.toolStrip1, toolStrip);
        }

In the MDI Child form I have two methods:

        private void MergeToolStrip()
        {
            IToolStripHost host = (IToolStripHost)this.ParentForm;
            host.AppendToolStrip(this.toolStrip1);
        }

        private void UnmergeToolStrip()
        {
            IToolStripHost host = (IToolStripHost)this.ParentForm;
            host.RemoveToolStrip(this.toolStrip1);
        }

These methods are called from the Shown/Activate/Deactivate/FormClosing
event handlers

There is some screen flicker. I am open to critique from my fellow peers.

currently I have *no* save toolStripItem in the parent Form's ToolStrip, it
is in the child Form's. I think I would prefer that the parent has a
disabled save ToolStripItem that is replaced by the child's enabled one. So
  I'm working on that now, this may reduce the paint flicker issue.