for (int i = 1; i < 101; i++) { Control c = this.Controls["t"+i.ToString()]; if (c != null) { MessageBox.Show(c.Text); } }
for (int i = 1; i <= 100; i++) { Control ctrl = this.Controls.Find("t" + i, false)[0]; // 类型转换成某控件,或直接提取共有属性,比如 ctrl.Text }
foreach (Control item in this.Controls) { item.Text; }
foreach (System.Windows.Forms.Control control in this.groupBox2.Controls)//遍历groupBox2上的所有控件 { if (control is System.Windows.Forms.TextBox) { System.Windows.Forms.TextBox tb= (System.Windows.Forms.TextBox)control; //想做的事..... } //其他类型的控件 }
for (int i = 1; i < 101; i++)
{
Control c = this.Controls["t"+i.ToString()];
if (c != null)
{
MessageBox.Show(c.Text);
}
}
{
Control ctrl = this.Controls.Find("t" + i, false)[0];
// 类型转换成某控件,或直接提取共有属性,比如 ctrl.Text
}
{
item.Text;
}
{
if (control is System.Windows.Forms.TextBox)
{
System.Windows.Forms.TextBox tb= (System.Windows.Forms.TextBox)control;
//想做的事.....
}
//其他类型的控件
}