如何在TableLayoutPanel中找到控件的索引



我想用RemoveAt(Int32 index(方法从一行中删除所有控件,但我不知道哪个索引有任何控件。

我认为TableLayoutPanel中的控件与table中的控件类似:在一行中,从第一列开始,一直到最后一列。,然后我们去下一排,做同样的动作。所以我认为每个控件的指标都可以计算出来:selectedRow * RowCount + selectedColumn但我发现这个方法是不正确的,所以我试图找出如何获得控件的索引。

提前感谢!!!

下面是吉米所说的一个例子:

private void allButtons_Click(object sender, EventArgs e)
{
Button btn = (Button)sender;
int row = tableLayoutPanel1.GetRow(btn);
for(int i=0; i<tableLayoutPanel1.ColumnCount; i++)
{
tableLayoutPanel1.GetControlFromPosition(i, row).Dispose();
// or, if you need to keep those controls for later use
Control ctl = tableLayoutPanel1.GetControlFromPosition(i, row);
// ...store each "ctl" somewhere...
tableLayoutPanel1.Controls.Remove(ctl);
}
}

相关内容

最新更新