tags:

views:

232

answers:

2

Im currently adding toolstrips from my seperate modules like:

this.toolStripContainer.TopToolStripPanel.Controls.Add(module.Instance.Toolbar)

Buy they are then in the order that the modules are loaded which isnt very good. Is there any way to re-order them?

Or should i be looking at adding some sort of index to my modules and laoding them in the order that i want the toolstrips?

+1  A: 

The Controls collection has a SetChildIndex(Control child, int newIndex) method. See if you can use that method to order the controls as per your need.

EDIT: Just did a quick test. You need to call SuspendLayout() before adding the controls and then ResumeLayout() once you're done:

        this.toolStripContainer1.TopToolStripPanel.SuspendLayout();
        this.toolStripContainer1.TopToolStripPanel.Controls.Add(t1);
        this.toolStripContainer1.TopToolStripPanel.Controls.Add(t2);
        this.toolStripContainer1.TopToolStripPanel.Controls.SetChildIndex(t1, 1);
        this.toolStripContainer1.TopToolStripPanel.ResumeLayout();
BFree
SetChildIdex appears to have no effect, should i be re-freshing the control or something?
Tim
Maybe try putting a call to SuspendLayout() before adding and reordering, and then a ResumeLayout after you're done: this.toolStripContainer1.TopToolStripPanel.SuspendLayout();
BFree
it seems to work, but i have to cycle through the modules twice, once to add them, and then again to set the index.
Tim
A: 

I ended up adding all the toolstrips to a list... sorting the list by ToolStrip.Tag... and then adding them to the control list...

This allows the module writer to set a priority for the toolstrip, kind of like toolstrip merging

Tim