以下是核心代码
private void button4_Click(object sender, EventArgs e) { Control.ControlCollection sonControls = panel1.Controls; //遍历所有控件 foreach (Control control in sonControls) { string s = control.Name;//获得控件名称 string s2 = control.GetType().ToString();//得到控件的类型名称 bool b = (s2.Contains("TextBox")); } }