我有一个包含2列4行的TableLayoutPanel,我想在运行时向其中添加按钮。我希望每个按钮都能动态地添加到第一格中:
private int nextIndex = 1;
private void bAddButton_Click(object sender, EventArgs e)
{
Button newButton = new Button();
newButton.Text = nextIndex.ToString();
tableLayoutPanel1.Controls.Add(newButton, 0, 0); // first cell
nextIndex++;
}
据我理解,这应该将所有现有的按钮向上移动一个单元格。这似乎在前三次操作中是有效的,但之后它会将新按钮插入到第2个单元格几次,然后是第3个单元格,然后是第4个单元格等等...
对于给定的单元格,您可以调用Controls.Add(ctrl, column, row)的次数是否有限制?
我有点困惑,我做错了什么?