如何获取特定类型的Windows窗体(Button/TextBox)的所有子控件?我需要在x类型的表单上获得所有控件。dim ctrls() as Controlctrls = Me.Controls(GetType(TextBox))我知道我可以使用递归函数迭代所有控件-获取子控件,但是是否有更简单或更简单的方法,比如下面的内容?Dim Ctrls = From ctrl In Me.Controls Where ctrl.GetType Is Textbox
3 回答
ABOUTYOU
TA贡献1812条经验 获得超5个赞
private void Test() { List<Control> allTextboxes = GetAllControls(this); } private List<Control> GetAllControls(Control container, List<Control> list) { foreach (Control c in container.Controls) { if (c is TextBox) list.Add(c); if (c.Controls.Count > 0) list = GetAllControls(c, list); } return list; } private List<Control> GetAllControls(Control container) { return GetAllControls(container, new List<Control>()); }
- 3 回答
- 0 关注
- 945 浏览
添加回答
举报
0/150
提交
取消