• 如何根据name来找到control/component?


            private Component findcompents(Component ctl, string name)
            {
                var flag = BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public;
    
                var fields = ctl.GetType().GetFields(flag).Where(x => x.FieldType.IsSubclassOf(typeof(Component)));
                var findfiled = fields.FirstOrDefault(x => x.Name == name);
                if (findfiled != null) return findfiled.GetValue(ctl) as Component;
    
                foreach (FieldInfo f in fields)
                {
                    var val = f.GetValue(ctl) as Component;
                    if (val != null) return findcompents(val, name);
                }
    
                return null;
            }
    
            private void button1_Click(object sender, EventArgs e)
            {
                bool value = false;
                string property = "Visible";
                DateTime dt = DateTime.Now;
                var a = findcompents(this, "gridColumn1");
    
                if (property == "Enabled")
                {
                    a.SetEnabled(value);
                }
                else if (property == "ReadOnly")
                {
                    if (!a.SetReadOnly(value))
                    {
                        if (a is DevExpress.XtraEditors.BaseEdit)
                            (a as DevExpress.XtraEditors.BaseEdit).Properties.ReadOnly = !value;
                        else if (a is DevExpress.XtraGrid.Columns.GridColumn)
                            (a as DevExpress.XtraGrid.Columns.GridColumn).OptionsColumn.AllowEdit = value;
                    }
                }
                else if (property == "Visible")
                {
                    if (!a.SetVisible(value))
                    {
                        var visible = value ? BarItemVisibility.Always : BarItemVisibility.Never;
    
                        if (a is DevExpress.XtraBars.BarItem)
                            (a as DevExpress.XtraBars.BarItem).Visibility = visible;
                    }
                }
            }

    应用:可以通过配置界面上的控件的name,来控制其一些常用属性!(必须要支持所有控件和组件,对可写,禁用,隐藏等常用属性控制)

    暂且没有什么好办法,先保留一份,以后再思考!

  • 相关阅读:
    cookie的过期时间
    Cookie的使用及位置
    用存储过程进行的查询拼接
    验证码的使用
    SQLHelper
    App_code的引用
    GridView使用
    javascript、ajax验证
    数据库小结(三)
    数据库操作(七)存储过程
  • 原文地址:https://www.cnblogs.com/zhahost/p/2889859.html
Copyright © 2020-2023  润新知