C#添加行时,表格布局的高度会加倍?
我有一个tableLayout,每次单击按钮时,我都会向其中添加一行 但是,当我添加无法放入tableLayout的行时,它会水平扩展,这很好。 但是,每次它“扩展”(当滚动条填充到最大值时),它会扩展到两倍的大小,而不仅仅是1行的高度 我将注意力集中在第五行,这样如果表一次只能显示5个,那么用户将在屏幕上显示5个,在顶部显示5个空闲。 然后他们可以向下滚动查看所有旧的行,因为这些行是自下而上添加的 有什么想法吗C#添加行时,表格布局的高度会加倍?,c#,tablelayout,C#,Tablelayout,我有一个tableLayout,每次单击按钮时,我都会向其中添加一行 但是,当我添加无法放入tableLayout的行时,它会水平扩展,这很好。 但是,每次它“扩展”(当滚动条填充到最大值时),它会扩展到两倍的大小,而不仅仅是1行的高度 我将注意力集中在第五行,这样如果表一次只能显示5个,那么用户将在屏幕上显示5个,在顶部显示5个空闲。 然后他们可以向下滚动查看所有旧的行,因为这些行是自下而上添加的 有什么想法吗 private void button1_Click(object sender
private void button1_Click(object sender, EventArgs e)
{
Addlabel("message", "response");
}
private void Addlabel(String message, string response)
{
Label messageLbl = new Label();
messageLbl.Dock = DockStyle.Fill;
messageLbl.Text = message;
messageLbl.Font = new Font("Tahoma", 12.0F);
Label responseLbl = new Label();
responseLbl.Dock = DockStyle.Fill;
responseLbl.Text = response;
responseLbl.Font = new Font("Tahoma", 12.0F);
messageLbl.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
messageLbl.BorderStyle = BorderStyle.FixedSingle;
responseLbl.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
responseLbl.BorderStyle = BorderStyle.FixedSingle;
tableLayoutPanel1.Controls.Add(messageLbl, 0, tableLayoutPanel1.RowCount);
tableLayoutPanel1.Controls.Add(responseLbl, 1, tableLayoutPanel1.RowCount);
tableLayoutPanel1.RowCount++;
tableLayoutPanel1.VerticalScroll.Value = 5;
}
您需要指定要添加的行的高度,即:
tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle (System.Windows.Forms.SizeType.Absolute, 20F));
注意:绝对值表示行的高度是固定大小,其他情况下,您使用的百分比将允许其展开