2 回答

TA貢獻(xiàn)1877條經(jīng)驗(yàn) 獲得超6個(gè)贊
private int FindLabelCount()
{
return FindLabelCount(this);
}
private int FindLabelCount(Control control)
{
int count = 0;
if (control.HasChildren)
{
foreach (Control child in control.Controls)
{
if (child is Label)
{
count++;
}
count += FindLabelCount(child);
}
}
return count;
}
使用int count = FindLabelCount();就可以獲取

TA貢獻(xiàn)1815條經(jīng)驗(yàn) 獲得超13個(gè)贊
foreach(Control ctl in this.Controls)
{
if(ctl is Label)
//找到Label控件了。
}
- 2 回答
- 0 關(guān)注
- 487 瀏覽
添加回答
舉報(bào)