【问题标题】:Add ToolStripMenuItem in new row when one row is filled inside ToolStrip当 ToolStrip 中填满一行时,在新行中添加 ToolStripMenuItem
【发布时间】:2013-07-12 07:13:51
【问题描述】:

我有一个表单,在表单内部我有一个工具条控件,并且我正在动态添加 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);

        }

如果你不明白我想要什么,请告诉我。

任何建议我怎样才能做到这一点。 谢谢。

【问题讨论】:

    标签: c# toolstrip toolstripmenu


    【解决方案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);
    

    【讨论】:

      猜你喜欢
      • 2012-05-24
      • 1970-01-01
      • 2016-08-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-01
      相关资源
      最近更新 更多