如何在C#中访问找到所有控件和所有组件的表格? [英] How to access find all controls and all components into form in C#?
本文介绍了如何在C#中访问找到所有控件和所有组件的表格?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个窗口窗体,其中包含一些控件和一些组件(例如DataTable,XPCollection等).我想找到在此表单中使用的所有控件名称和组件名称.
I have a window form which contain some Controls an some Components ( like DataTable, XPCollection etc). I would like find all Control Names and Component Names which used into this form.
推荐答案
您可以做到,
List<string> ctrlNames = new List<string>();
FIndAllCtrls(ctrlNames , this.Controls);
private void FIndAllCtrls(ctrlNames, ControlCollection ctrlColl)
{
foreach(Control ctrl in ctrlColl)
{
ctrlNames.Add(ctrl.Name);
if(ctrl.Controls.Count > 0)
FIndAllCtrls(ctrlNames, ctrl.Controls);
}
}
这篇关于如何在C#中访问找到所有控件和所有组件的表格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文