foreach(Control s in this.Controls)
{
if(s.GetType()==typeof(TextBox))
{
((TextBox)s).Text ="hello";
}
}

解决方案 »

  1.   

    private void button1_Click_2(object sender, System.EventArgs e)
    {
    changeText(this.Controls);
    } private void changeText(System.Windows.Forms.Control.ControlCollection control)
    {
    foreach(Control c in control)
    {
    if(c.GetType()==typeof(System.Windows.Forms.TextBox))
    {
    c.Text="Hello";
    }
    if(c.Controls.Count>0)
    {
    changeText(c.Controls);
    }
    }
    }还要考虑有些控件是控件的容量,里面还有控件,
    所以要用递归。
      

  2.   

    TextBox控件放数组里,就简单了
    txtBox[i].Text="tb"+i;