• (学)递归查找窗体中全部控件


    /// <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
                { }
            }
  • 相关阅读:
    登录不了路由器恢复办法
    刷完OpenWrt在浏览器无法访问的解决办法
    [海蜘蛛] 海蜘蛛 V8 全线无限试用版 免费发布破解教程
    ThinkPHP3.0启动过程
    ivr
    centos6.5下修改文件夹权限和用户名用户组
    从一条巨慢SQL看基于Oracle的SQL优化(重磅彩蛋+PPT)
    基于Docker搭建MySQL主从复制
    Elasticsearch全文检索实战小结
    springboot-Learning
  • 原文地址:https://www.cnblogs.com/spymaster/p/8303399.html
Copyright © 2020-2023  润新知