遍歷控件的屬性ctrl.GetType().GetProperties()

 

PropertyInfo[]   propertys   =   new    myClass().GetType().GetProperties();  
即可獲得對象myClass的所有屬性組成的集合 propertys 

 

       //獲取控件屬性
        public void GetCtrAttribute(Control ctrl)
        {
            if (ctrl != null)
            {
                dataGridView1.Tag = ctrl;
                dataGridView1.Rows.Clear();
                System.Reflection.PropertyInfo[] pp = ctrl.GetType().GetProperties();
                foreach (System.Reflection.PropertyInfo p in pp)
                {
                    dataGridView1.Rows.Add(p.Name, p.GetValue(ctrl, null));
                    // Console.WriteLine("Name:{0} Value:{1}", p.Name, p.GetValue(c,null));
                }


          }


 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章