c# 遍历控件及子控件

private void PrintChildControls(Control control)
{
foreach (Control child in control.Controls)
{
Console.WriteLine(child.Name);

PrintChildControls(child); // 递归遍历子控件
}
}

private void button1_Click(object sender, EventArgs e)
{
PrintChildControls(this);
}

分类:

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注