MDI Merging /w ToolStrip and ToolStripContainer

Hello!

Using Whidbey Beta 2 I built a simple MDI App with Menu- and ToolStrip-Controls on the Parent and on the Child. If the Child Form is shown, the MenuItems and the Tool-Items itself  are correctly merged with the main Tool-/MenuStrips placed on the MDI Parent. 

But on the MDI Child an empty MenuStrip and an empty ToolStrip are still present. I found no documentation to make the Strip-Containers disapear if the Items of the Strips are merged with a "parent Strip".

It doesn't matter whether the Strips are placed directly on the Form or wrapped by an ToolStripContainer.

Is this a BUG or has anyone an idea or workaround

Thx for any suggestions!


Answer this question

MDI Merging /w ToolStrip and ToolStripContainer

  • cost7615

    That is amazingy helpful. I almost redid my entire program!!!

    Is there one for a MenuStrip

  • Janmre

    Yes, this works! Thx a lot!

    Stefan

  • Hoang Nguyen

    Thanks for the info. That does work!

    However, it still seems to me that if I set AllowMerge to true on the both the parent and child forms, it should merge and unmerge the toolstrip automatically as I toggle between MDI forms (as it did in the Whidbey version). That's the behavior I would expect. Is this a bug in the new version, or was it a bug in the Whidbey version I personally like the way it worked in Whidbey better.

  • Feng Chun

    Did you try to fix it with

    ToolStripManager.Merge(..., ...);


  • GoldnGreen

    Thanks, that really helped. What I now have is:



    private
    void MDIParent1_MdiChildActivate(object sender, EventArgs e)

    {

    //...

    //Merge

    ToolStripManager.RevertMerge(toolStrip);

    ToolStripManager.RevertMerge(menuStrip);

    if (this.ActiveMdiChild != null)

    {

    if ((ActiveMdiChild as ICipherInputForm).CipherToolStrip != null)

    ToolStripManager.Merge((ActiveMdiChild as ICipherInputForm).CipherToolStrip, toolStrip);

    if ((ActiveMdiChild as ICipherInputForm).CipherMenuStrip != null)

    ToolStripManager.Merge((ActiveMdiChild as ICipherInputForm).CipherMenuStrip, menuStrip);

    }


     

    An interface



    public interface ICipherInputForm

    {

    //...

    System.Windows.Forms.ToolStrip CipherToolStrip

    {

    get;

    }

    System.Windows.Forms.MenuStrip CipherMenuStrip

    {

    get;

    }

    }



     


    And in each mdiChild I have


    public ToolStrip CipherToolStrip

    {

    get

    {

    return toolStrip1;

    }

    }

    /// <summary>

    /// The toolStrip that this cipher uses to display UI

    /// </summary>

    public MenuStrip CipherMenuStrip

    {

    get

    {

    return menuStrip1;

    }

    }



     


    Pitty they didn't just leave automerging in. Oh well.



  • warp9.5

    I was doing the exact same thing in Whidbey Beta 2 (MDI toolstrip merging into parent form toolstrip). But now I'm using the newly released VS 2005 and this no longer works. Because I have both a menustrip and a toolstrip, I set the menustrip as the MainMenuStrip in my parent form. Is the MainMenuStrip the only thing that will merge now In my case, I want both the main menu and the toolbar to merge.

    Thanks in advance.

  • cs96ai


    MenuStrips/ToolStrips in the MDIChildren should be set to visible=false. Hope that helps.

  • Vernon in Middlewich

     Julie2 wrote:
    I was doing the exact same thing in Whidbey Beta 2 (MDI toolstrip merging into parent form toolstrip). But now I'm using the newly released VS 2005 and this no longer works. Because I have both a menustrip and a toolstrip, I set the menustrip as the MainMenuStrip in my parent form. Is the MainMenuStrip the only thing that will merge now In my case, I want both the main menu and the toolbar to merge.

    Thanks in advance.


    Hi, Julie
    I have the same problem... trying to solve, then reply to you:)

  • Randy Cragin

    Yes! this surprised me too.  I had fully functioning tool/menu merge in place and couldn't immediately see the answer.  Thanks for the tip above.

    I've updated my application (works for Tool & Menu strips - see Remarks in http://msdn2.microsoft.com/library/5523fet0)

    You also need to unset (revert) the merge when MDI child forms close.  You can get the main menu from an MDI child if you set its MainMenuStrip property E.g.

    MainMenuStrip = myMenuStrip;


    I cannot find a toolstrip equivalent, so I put a public "get" property in the MDI child form to get the toolstrip.

    I've ended up with the following MDI parent child activate event like this

    private void FormMainMDI_MdiChildActivate(object sender, EventArgs e)

    {

    SetFormText();

    // unmerge the toolbar and menu from the child as an existing one has gone

    ToolStripManager.RevertMerge(TS1);

    ToolStripManager.RevertMerge(MB1);

    if (this.ActiveMdiChild != null)

    {

    // set the icon to match the child

    this.Icon = this.ActiveMdiChild.Icon;

    ToolStripManager.Merge(((YourChildForm)this.ActiveMdiChild).ToolStrip, TS1);

    ToolStripManager.Merge(ActiveMdiChild.MainMenuStrip, MB1);

    }

    else

    {

    // set the default icon

    this.Icon = CustomControls.Helpers.GetIcon("YourDefault.ico");

    }

    // need to get my recent files when unmerging - it loses all knowledge of them as the menu item is dynamically created

    _recentFiles = new RecentFiles();

    }

    Hope this helps


  • MDI Merging /w ToolStrip and ToolStripContainer