我有一个表单和内部表单我有一个工具条控件,我正在动态添加ToolStripMenuItem。 我想要的是当一个人填满时,项目应列在下一行。 我试过这个来增加表单的高度和宽度,但是在新行中添加项目没有发生。
ToolStripItemCollection t_col = toolStripTaskBar.Items;
int _howMany = t_col.Count;
Rectangle mi_bounds = t_col[_howMany - 1].Bounds;
if (this.Width < (mi_bounds.X + mi_bounds.Width))
{
int minimumFormHeight = 80;
this.MinimumSize = new Size((mi_bounds.X + mi_bounds.Width), minimumFormHeight);
}
如果你不明白我的意思,请告诉我。
任何建议我如何实现这一目标。 谢谢。
答案 0 :(得分:1)
您可以使用ToolStrip的LayoutStyle属性。您需要将其设置为表并修改布局设置(指定行数和列数)。
你可以这样做:
this.toolStrip1.LayoutStyle = ToolStripLayoutStyle.Table;
var layoutSettings = (this.toolStrip1.LayoutSettings as TableLayoutSettings);
layoutSettings.ColumnCount = 3;
layoutSettings.RowCount = 3;
您可以向工具栏中添加新项目:
var item = new ToolStripMenuItem(string.Format("item{0}", this.toolStrip1.Items.Count + 1));
this.toolStrip1.Items.Add(item);