2013-07-12 123 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); 
相關問題