我想新建一個窗體,然后在窗體中拖幾個 label,我想用代碼計(jì)算出form窗體中l(wèi)abel中的個數(shù),希望各高手幫助解決下。
2 回答
慕哥9229398
TA貢獻(xiàn)1877條經(jīng)驗(yàn) 獲得超6個贊
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個贊
foreach(Control ctl in this.Controls)
{
if(ctl is Label)
//找到Label控件了。
}
- 2 回答
- 0 關(guān)注
- 496 瀏覽
添加回答
舉報(bào)
0/150
提交
取消
