先来一个效果图:
运行前:
运行后:
算上展示的label就是展示的总数量。
代码例下:
///
///
///
///
///
private int GetLabelCount(System.Windows.Forms.Control parentCountol)//获取某种控件在页面中的数量
{
//TabPage
int LabelCount = 0;
foreach (System.Windows.Forms.Control c in parentCountol.Controls)
{
if (c is System.Windows.Forms.Label)
{
LabelCount++;
}
LabelCount += GetLabelCount(c);
}
return LabelCount;
}
private void button1_Click(object sender, EventArgs e)
{
int LabelCount = GetLabelCount(this);//获取窗体中label控件
this.label6.Text = Convert.ToString(LabelCount);
}



