Question

I have one form and inside form i have one toolstrip control, and i am adding ToolStripMenuItem dynamically. What i want is when one is filled up, items should list in next row. I tried this for increasing the height and width of form but adding items in new row not happening.

 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);

        }

Let me know if you not understand what i want.

Any suggestion how can i achieve this. Thank You.

Était-ce utile?

La solution

You can use LayoutStyle property of ToolStrip. You need to set up it to Table and modify layout settings (specify rows and columns count).

You can do it like this:

this.toolStrip1.LayoutStyle = ToolStripLayoutStyle.Table;
var layoutSettings = (this.toolStrip1.LayoutSettings as TableLayoutSettings);
layoutSettings.ColumnCount = 3;
layoutSettings.RowCount = 3;

And the you can add new items to toolstrip:

var item = new ToolStripMenuItem(string.Format("item{0}", this.toolStrip1.Items.Count + 1));
this.toolStrip1.Items.Add(item);
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top