Making a Toolstripcontainer panel work like an MDI parent

Pyro picture Pyro · Mar 29, 2012 · Viewed 7.6k times · Source

This is for C# and I am working in a Windows 7 environment with Visual Studio Express 2010. I have an application where I have a toolstripcontainer dock set to fill so users can add toolstrips on any edge. The problem was that the toolstripcontainer has covered the that I want to use for holding sub-windows. The primary form containing the toolstripcontainer has been set as an mdi parent. I found this article useful in getting the sub-windows into the container: How to uses a ToolStripContainer whith Dock=Fill on a MDI parent?

However, sub-windows done in this way don't seem to behave as they should in the 'native' MDI environment. The boarders look as though the windows 7 Aero effect has been disabled and minimising the sub-window makes it disappear entirely.

Essentially I want an MDI area for sub-windows surrounded by toolstrip docking areas.

Thanks a lot for your help

Answer

LarsTech picture LarsTech · Mar 29, 2012

Unfortunately, the ToolStripContainer control was not meant to work with an MDI form.

Try using the ToolStripPanel control instead. It doesn't work too well in the designer (which is probably why it isn't in the ToolBox by default).

Example:

public partial class Form1 : Form {

  public Form1() {
    InitializeComponent();

    this.IsMdiContainer = true;
    ToolStripPanel leftPanel = new ToolStripPanel() { Dock = DockStyle.Left };
    ToolStripPanel topPanel = new ToolStripPanel() { Dock = DockStyle.Top };
    this.Controls.Add(leftPanel);
    this.Controls.Add(topPanel);

    ToolStrip ts = new ToolStrip() { Dock = DockStyle.Fill };
    ToolStripButton tsb = new ToolStripButton("Test", SystemIcons.Application.ToBitmap());
    ts.Items.Add(tsb);

    topPanel.Controls.Add(ts);
  }
}