c# 通过属性设置控件的显示与否

PropertyInfo[] objTempArr;
            BindingFlags objFlag = (BindingFlags.Public | BindingFlags.Instance);
            try
            {
                objTempArr = this.GetType().GetProperties(objFlag);
                for (int i = 0; i < objTempArr.Length; i++)
                {
                    if (base.operations.Exists(s => s.Url == objTempArr[i].Name))
                    {
                        objTempArr[i].SetValue(this, true, null);
                    }
                    else
                    {
                        objTempArr[i].SetValue(this, false, null);
                    }

                }
            }
            catch (Exception err)
            {

                throw err;
            }

公开要控制的控件属性

public Boolean Button1Enabled
        {
            set { this.button1.Enabled = value; }
        }

        public Boolean Button2Enabled
        {
            set { this.button2.Enabled = value; }
        }
        public Boolean Button3Enabled
        {
            set { this.button3.Enabled = value; }
        }
        public Boolean Button4Enabled
        {
            set { this.button4.Enabled = value; }
        }

        public Boolean CheckBox1Enabled
        {
            set { this.checkBox1.Enabled = value; }
        }

        public Boolean TextBox1Endbled
        {
            set { this.textBox1.Enabled = value; }
        }

 

 

 

 

posted on 2013-05-15 10:17  AlexGeng  阅读(471)  评论(0编辑  收藏  举报

导航