111,119
社区成员
发帖
与我相关
我的任务
分享 foreach (Control item in this.Controls )
{
Console.WriteLine(item.Name);
}
Console.WriteLine("------------------");
foreach ( Control item in this.panel1.Controls)
{
Console.WriteLine(item.Name);
}
public void FindAllSubCtl(Control.ControlCollection collection)
{
for (int i = 0; i < collection.Count; i++)
{
Console.WriteLine("control current:" + collection[i].Name);
FindAllSubCtl(collection[i].Controls);
}
}
private void button1_Click(object sender, EventArgs e)
{
FindAllSubCtl(Controls);
}
//FindControl(this.Controls);
public void FindControl(System.Windows.Forms.Control.ControlCollection cc)
{
foreach (Control item in cc)
{
Console.WriteLine(item.Name); n += 1;
if (item.HasChildren){ FindControl(item.Controls);}
//if (item.Controls.Count > 0) { FindControl(item.Controls); }
//if (item.Controls != null) { FindControl(item.Controls); }
}
}