zoukankan      html  css  js  c++  java
  • (学)递归查找窗体中全部控件

    /// <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
                { }
            }
  • 相关阅读:
    LINUX查看硬件配置命令
    jmeter录制对于ip代理会失效
    性能测试常用指标
    jmeter使用jdbc获取注册验证码进行注册
    jmeter测试文件上传功能
    JMeter 功能挖掘之 WEB 文件导出
    分别用C/C++实现栈
    javascript的倒计时功能中newData().getTime()在iOS下会报错问题解决
    jquery解决file上传图片+图片预览
    使用SetInterval时函数不能传参问题
  • 原文地址:https://www.cnblogs.com/spymaster/p/8303399.html
Copyright © 2011-2022 走看看