2013-07-12 77 views
0

我有一种形式和内部形式,我有一个工具栏控件,并且我正在动态添加ToolStripMenuItem。 我要的是当一个人被填满,项目应在下一行列出。 我试图增加窗体的高度和宽度,但在新行中没有发生添加项目。当ToolStrip里面填充一行时,在新行中添加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); 

     } 

让我知道如果你不明白我想要什么。

任何建议我怎么能实现这一点。 谢谢。

回答

1

您可以使用ToolStrip的LayoutStyle属性。您需要将其设置为Table并修改布局设置(指定行数和列数)。

你可以这样说:

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); 
相关问题