I've got a really weird problem with ToolStripPanel.Join and I've been searching on Google and SO for some clue as to what I'm doing wrong but I can't figure it out. Basically, when I use ToolStripPanel.Join, the first ToolStrip that I add doesn't appear at all in the ToolStripPanel but all other ToolStrips that I join will appear. Before I get too far into the details, let me first say that I'm using C# and VS 2010 and .NET 4 and, just for some context, I'm trying to use a ToolStripPanel on a user control which is inside of a custom dll that we made so that we could reuse these user controls in other forms.
I was previously using a ToolStripContainer but I decided to switch out to use a ToolStripPanel since we only really needed the top panel of the ToolStripContainer; I didn't see the point of using a ToolStripContainer. Since I couldn't find a ToolStripPanel control in the Toolbox, I decided to add it myself in the Designer.cs file. Here's how I did it:
private ToolStripPanel tsPanel;
<--Other code here-->
private void InitializeComponent()
{
this.tsPanel = new System.Windows.Forms.ToolStripPanel();
<--Other code here-->
//
// tsPanel
//
this.tsPanel.Dock = System.Windows.Forms.DockStyle.Top;
this.tsPanel.Location = new System.Drawing.Point(0, 0);
this.tsPanel.Margin = new System.Windows.Forms.Padding(3);
this.tsPanel.Name = "tsPanel";
this.tsPanel.Orientation = System.Windows.Forms.Orientation.Horizontal;
this.tsPanel.RowMargin = new System.Windows.Forms.Padding(3, 0, 0, 0);
this.tsPanel.Size = new System.Drawing.Size(1000, 0);
<--Other code here-->
//
// MFDesigner
//
this.BackColor = System.Drawing.Color.Gainsboro;
<--Add other controls to UC Controls collection-->
this.Controls.Add(this.tsPanel);
this.ForeColor = System.Drawing.Color.Black;
this.Name = "MFDesigner";
this.Size = new System.Drawing.Size(1000, 670);
this.Load += new System.EventHandler(this.MultiFormatDesignerControl_Load);
this.Resize += new System.EventHandler(this.MFDesigner_Resize);
this.pnlToolbox.ResumeLayout(false);
this.pnlProperties.ResumeLayout(false);
this.ResumeLayout(false);
this.PerformLayout();
}
Then, in the user control's constructor, I have:
public MFDesigner()
{
InitializeComponent();
<--Other code here-->
ToolStripButton[] openSaveButtonArr = new ToolStripButton[]{
//The createToolStripButton method creates toolstrip buttons using some simple
//parameters.
createToolStripButton("Open", Images.CmdOpen, new EventHandler(this.OnOpen), "Open saved file"),
createToolStripButton("Save", Images.CmdSave, new EventHandler(this.OnSaveToDisk), "Save to disk")
};
ToolStrip openSaveToolStrip = new ToolStrip(openSaveButtonArr);
tspanel.Join(openSaveToolStrip);
<--Other code here-->
}
Since we're creating tool strips and adding them to the toolstrippanel in code, I can't see what it looks like in the designer for the user control. So, I build the dll and I go over to another form in a separate project that consumes the user control from the dll and when the form opens, there is no toolstrip; it simply doesn't appear. Here's the weird thing, though. If I add just one more toolstrip to the panel, the second toolstrip will appear:
public MFDesigner()
{
InitializeComponent();
<--Other code here-->
ToolStripButton[] openSaveButtonArr = new ToolStripButton[]{
//The createToolStripButton method creates toolstrip buttons using some simple
//parameters.
createToolStripButton("Open", Images.CmdOpen, new EventHandler(this.OnOpen), "Open saved file"),
createToolStripButton("Save", Images.CmdSave, new EventHandler(this.OnSaveToDisk), "Save to disk")
};
ToolStrip openSaveToolStrip = new ToolStrip(openSaveButtonArr);
tspanel.Join(openSaveToolStrip, 1);
ToolStripButton[] openSaveButtonArr2 = new ToolStripButton[]{
createToolStripButton("Open2", Images.CmdOpen, new EventHandler(this.OnOpen), "Open saved rpx file 2"),
createToolStripButton("Save2", Images.CmdSave, new EventHandler(this.OnSaveToDisk), "Save to disk 2")
};
ToolStrip openSaveToolStrip2 = new ToolStrip(openSaveButtonArr2);
tsPanel.Join(openSaveToolStrip2, 1);
<--Other code here-->
}
In the code above, the first toolstrip that I create will not appear, but the second one (openSaveToolStrip2) will appear. Incidentally, if I just use the Join overload Join(toolStrip) for both of the toolstrips, nothing appears. Also, if I add toolstrips to other rows, i.e. tsPanel.Join(toolstrip3, 2) or tsPanel.Join(toolstrip4, 3), the toolstrips will appear.
It seems like, for some inexplicable (for me, at least) reason, the first toolstrip that I add never appears but all subsequent toolstrips do. As a workaround, I've been just creating a dummy toolstrip, adding it, then adding all of my real toolstrips. This feels pretty hacky so I'd love to figure out why this is happening. I've tried to follow the documentation on MSDN but I must still be missing something because I can't imagine a bug like this not getting fixed.
Does anybody know what might be going wrong here?