遍历所有控件和子控件
List<Control> allControl = new List<Control>();
private void GetControl(Control.ControlCollection ctc)
{
foreach (Control ct in ctc)
{
allControl.Add(ct);
//当控件有子控件时,需要用递归的方法遍历
if (ct.HasChildren)
{
GetControl(ct.Controls);
}
}
}
调用 GetControl(form.controls) 遍历窗体所有控件。