我目前从我的单独模块中添加工具条,例如:
this.toolStripContainer.TopToolStripPanel.Controls.Add(module.Instance.Toolbar)
然后按照加载模块的顺序购买它们,这不是很好。有没有办法重新订购它们?
或者我应该考虑为我的模块添加某种索引并按照我想要工具条的顺序加载它们?
Controls 集合有一个SetChildIndex(Control child, int newIndex)方法。看看您是否可以使用该方法根据您的需要订购控件。
编辑:刚刚做了一个快速测试。您需要在添加控件之前调用 SuspendLayout(),然后在完成后调用 ResumeLayout():
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();
我这样解决:
StripContainer.TopToolStripPanel.Join(
Instance.MMethod.Main.ToolStripMenu,
StripContainer.TopToolStripPanel.Controls[
StripContainer.TopToolStripPanel.Controls.Count - 1].Right,
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