1

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?

Tim
  • 7,746
  • 3
  • 49
  • 83

3 Answers3

3

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
  • 102,548
  • 21
  • 159
  • 201
  • SetChildIdex appears to have no effect, should i be re-freshing the control or something? – Tim Jun 03 '09 at 15:01
  • Maybe try putting a call to SuspendLayout() before adding and reordering, and then a ResumeLayout after you're done: this.toolStripContainer1.TopToolStripPanel.SuspendLayout(); – BFree Jun 03 '09 at 15:33
  • 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 Jun 03 '09 at 15:58
0

I solved like this:

StripContainer.TopToolStripPanel.Join(
    Instance.MMethod.Main.ToolStripMenu,
    StripContainer.TopToolStripPanel.Controls[
        StripContainer.TopToolStripPanel.Controls.Count - 1].Right, 
    0);
Lee Taylor
  • 7,761
  • 16
  • 33
  • 49
0

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
  • 7,746
  • 3
  • 49
  • 83