发布时间:2017-09-22编辑:佚名阅读(2413)
private void button1_Click(object sender, EventArgs e) { this.listBox1.Items.Clear(); GetControls1(this); GetControls2(this); } private void GetControls1(Control fatherControl) { Control.ControlCollection sonControls = fatherControl.Controls; //遍历所有控件 foreach (Control control in sonControls) { listBox1.Items.Add(control.Name); //递归 GetControls1(control); } } private void GetControls2(Control fatherControl) { //反射 System.Reflection.FieldInfo[] fieldInfo = this.GetType().GetFields(System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance); for (int i = 0; i < fieldInfo.Length; i++) { listBox2.Items.Add(fieldInfo[i].Name); } }
0人
0人
0人
0人