Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Making a Toolstripcontainer panel work like an MDI parent

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

like image 399
Pyro Avatar asked Mar 29 '12 13:03

Pyro


1 Answers

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);
  }
}
like image 100
LarsTech Avatar answered Oct 29 '22 14:10

LarsTech