111,129
社区成员
发帖
与我相关
我的任务
分享 private void GetControl(Control.ControlCollection ctc)
{
foreach (Control ct in ctc)
{
//C# 只遍历窗体的子控件,不遍历孙控件
//当窗体上的控件有子控件时,需要用递归的方法遍历,才能全部列出窗体上的控件
if (ct.HasChildren)
{
GetControl(ct.Controls);
}
}
}
//伪代码
void PrintCtrlName(Control parent)
{
foreach(Contrl ctrl in parent.Controls)
{
Print(ctrl.Name);
if(ctrl.Controls.Count >0)
{
PrintCtrlName(ctrl);
}
}
}