winform中我有100个控件,它的 id是按顺序来的(t1,t2,t3,t4,t5,t6,t7,t8,t9,t10.......)我现在要拿取它的值怎么拿取用什么方法

解决方案 »

  1.   


                for (int i = 1; i < 101; i++)
                {
                    Control c = this.Controls["t"+i.ToString()];
                    if (c != null)
                    {
                        MessageBox.Show(c.Text);
                    }
                }
      

  2.   

    for (int i = 1; i <= 100; i++)
    {
        Control ctrl = this.Controls.Find("t" + i, false)[0];
        // 类型转换成某控件,或直接提取共有属性,比如 ctrl.Text
    }
      

  3.   

    foreach (Control item in this.Controls)
                {
                    item.Text;                 
                }
      

  4.   

    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;  
         //想做的事..... 
        } 
       //其他类型的控件
       }