开发者

Programmatically Adding Labels To Newly Created Row?

I'm adding rows in the following manner:

Table.RowCount 开发者_JAVA百科= Table.RowCount ++;
Table.RowStyles.Add(new RowStyle(System.Windows.Forms.SizeType.AutoSize));

How can I add a Label to each cell in this newly created row?


Use the TableLayoutControlCollection.Add Method. There's an overload that allows you to specify the row and column where the new Label will be added.

This snippet adds a row to a TLP and then adds a new Label to the first column of this new row:

    Label label = new Label();
    label.Name = "MyNewLabel";
    label.Text = "Added in my test";
    tableLayoutPanel1.RowCount++;
    tableLayoutPanel1.RowStyles.Add(new RowStyle());
    tableLayoutPanel1.Controls.Add(label, 0, tableLayoutPanel1.RowCount - 1);


When you create a label, by default it's not autosize, I tried it just today. Set the AutoSize property on the label to true and you might have more luck.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜