现在的位置: 首页 > 综合 > 正文

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

2012年09月23日 ⁄ 综合 ⁄ 共 739字 ⁄ 字号 评论关闭
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; }
        }

 

 

 

 

抱歉!评论已关闭.