(学)递归查找窗体中全部控件
2018-01-17 16:00
323 查看
/// <summary> /// 通过递归将控件及子级控件信息列为树形 /// </summary> /// <param name="pControl"></param> /// <param name="pControlName"></param> public void BuildControlTree(dynamic pControl, string pControlName = null) { try { string strConName = ""; if (pControl.Name == "" && pControl.Text == "") return; //if (PCon is DevExpress.XtraEditors.SplitGroupPanel) // strConName = PID + PCon.Text; //else // strConName = PCon.Name == "" ? PCon.Text : PCon.Name; strConName = (pControlName == null ? "" : pControlName + "-") + (pControl.Name == "" ? pControl.Text : pControl.Name); DataRow dr = dsControlTree.DT_ControlTree.NewRow(); dr["ID"] = strConName; dr["ParentID"] = pControlName; dr["ControlName"] = strConName; dr["ControlType"] = pControl.GetType().Name; dsControlTree.DT_ControlTree.Rows.Add(dr); //DicCon.Add(strConName, PCon); //插入其子控件 if (pControl is GridControl) { //循环其gridview foreach (GridView gv in pControl.Views) { BuildControlTree(gv, strConName); } } else if (pControl is GridView) { //循环其gridcolumn foreach (GridColumn gdc in pControl.Columns) { BuildControlTree(gdc, strConName); } } else if (pControl is LayoutControl) { return; } else if (pControl is TreeList) { //循环其TreeListColumn foreach (TreeListColumn tlc in pControl.Columns) { BuildControlTree(tlc, strConName); } } else { if (pControl is Control && pControl.Controls.Count > 0) { foreach (Control CCom in pControl.Controls) { BuildControlTree(CCom, strConName); } } } } catch { } }
相关文章推荐
- 查找窗体界面中的控件,递归查找等控件处理问题,多使用于权限设置管理。
- 递归清空窗体上 所有文本框,下拉框中的文本。(修改封装成控件)
- 如何遍历全部控件-递归方法
- C#如何在webBrowser1控件通过TagName,Name查找元素(没有ID时)遍历窗体元素
- 查找XAML中控件(递归)
- 窗体全部透明,控件不透明
- WinForm实现按名称递归查找控件的方法
- 在 Windows 窗体中查找控件
- WPF 应用Visual tree递归查找通用类的控件
- [原创]C#应用WindowsApi实现查找\枚举(FindWindow、EnumChildWindows)窗体控件,并发送消息。
- C#应用WindowsApi实现查找\枚举(FindWindow、EnumChildWindows)窗体控件,并发送消息。
- 窗体内查找webbrowser控件的句柄
- 在窗体上查找控件
- [转载]C#如何在webBrowser1控件通过TagName,Name查找元素(没有ID时)遍历窗体元素
- Winform中使用控件名来查找窗体或者容器中的控件
- C# 多个窗体之间查找控件
- 今天帮一个哥们弄的查找无标题窗体上的控件句柄的代码
- 递归清空窗体上 所有文本框,下拉框中的文本。(修改封装成控件)
- Winform中使用控件名来查找窗体或者容器中的控件
- 【Demo 0024】查找顶层窗体及控件