I have a toolstrip container with two toolstrips. I want to force one of them to be displayed on top of the other. I tried setting Dock to Top for one and to Bottom for the other, but they are still displayed randomly. I also tried using TopToolStripPanel.Controls.SetChildIndex(...) but it didn't have an effect. Even the same executable on two different pc's gives different order. Is there a way to force the order? Thanks
Asked
Active
Viewed 2,140 times
5
-
Any screen shot? Normally **We do need only 1 toolstrip**. Looks like you add your toolstrip dynamically using code? Because when you drag-n-drop 2 those toolstrips on your form, they would keep the order, I've worked with `Docking` fairly much, at least docking with other controls is OK, I don't think there is something special with `ToolStrip`, if it has, it **must be a bug** and solving an internal bug may end up for some ugly work-around. – King King Oct 09 '13 at 06:21
-
I dragged the two into the top panel in the toolstrip container. The order gets messed up at some point. Even after setting the Dock properties. – Jerry Oct 09 '13 at 11:49
-
Why don't you use normal `Panel` or simply don't use any container? – King King Oct 09 '13 at 12:29
1 Answers
2
Add these lines of code after InitializeComponent();
to your form's constructor to ensure your specific order. This fixes any messed up settings in the designer generated code:
toolStripContainer1.TopToolStripPanel.SuspendLayout();
toolStrip1.Dock = DockStyle.None;
toolStrip2.Dock = DockStyle.None;
toolStrip1.Location = new Point(0, 0);
toolStrip2.Location = new Point(0, toolStrip1.Height);
toolStripContainer1.TopToolStripPanel.ResumeLayout();

Andreas Adler
- 771
- 1
- 9
- 16