C# 查找指定名称的控件
private Control FindControl(Control container, string controlName) // 参数1为容器 参数2为控件名称 { if (container.Name == controlName) { return container;
private Control FindControl(Control container, string controlName) // 参数1为容器 参数2为控件名称
{
if (container.Name == controlName)
{
return container;
}
Control findControl = null;
foreach (Control control in container.Controls)
{ Console.WriteLine(control.Name);
if (control.Controls.Count == 0)
{
if (control.Name == controlName)
{
findControl = control; break;
}
}
else
{
findControl = FindControl(control, controlName);
if (findControl != null)
{
break;
}
}
}
return findControl;
}
更多推荐
所有评论(0)