【发布时间】:2008-10-27 13:50:46
【问题描述】:
我正在尝试以编程方式更改 TableLayoutPanel 中的行数(有时需要为 4,有时为 5,很少为 6)。
不幸的是,更改行数不会使RowStyles 集合保持同步,因此您无法设置新添加行的高度。下面的测试代码证明了这个事实:
private void button1_Click(object sender, EventArgs e)
{
//TableLayoutPanels start with 2 rows by default.
Debug.Assert(tableLayoutPanel1.RowStyles.Count ==
tableLayoutPanel1.RowCount);
//Cannot remove rows
tableLayoutPanel1.RowCount = 1;
Debug.Assert(tableLayoutPanel1.RowStyles.Count ==
tableLayoutPanel1.RowCount);
}
第二个断言失败。
private void button2_Click(object sender, EventArgs e)
{
//TableLayoutPanels start with 2 rows by default.
Debug.Assert(tableLayoutPanel1.RowStyles.Count ==
tableLayoutPanel1.RowCount);
//Cannot add rows
tableLayoutPanel1.RowCount = 6;
Debug.Assert(tableLayoutPanel1.RowStyles.Count ==
tableLayoutPanel1.RowCount);
}
第二个断言失败。
那么设置TableLayoutPanel 的RowCount 属性的正确编程方式是什么?
【问题讨论】:
-
@TheBlastOne 不; Stilll "关闭为推迟"
标签: .net winforms desktop-application