我以前看书上说可以把字符串型的"color"转换成变量弄的color,如:
string s="color";
***.color=+++[s].red;
其中***.color为一个对象的color属性,+++[]为对字符串s的处理(具体怎么处理的我忘记了),上面这句话就相当于***.color=color.red; 我想问有没有方法实现下面这个:将
textbox1=1;
textbox2=2;
textbox3=3;换成
for(int i=1;i<=3;i++)
{
    textbox*=i;   //*代表1、2...  
   //或是+++["textbox"+i]=i;
}这个想法能实现不?

解决方案 »

  1.   

    不太明白你的意图,下面代码可能对你有帮助string color="Red";
    Color.FromName(color);
      

  2.   


    int i = 0;
    foreach (System.Windows.Forms.Control c in this.Controls)
    {
       if (c is System.Windows.Forms.TextBox&&c.Name.StartsWith("textbox"))
       {
         (c as TextBox).Text = (c as TextBox).Name.Substring("textbox".Length);
       }
    }
      

  3.   


    1F的  FindControl["textbox" + i].text好像不行耶4F的  不大明白
    5F的  如果有人问过了,而且解决了的话,麻烦给个链接
      

  4.   

    写一段代码  里面有下面一段
    textbox1.text="1"
    textbox2.text="2"
    textbox3.text="3"
         .....
    textbox999.text="999"
    textbox1000.text="1000"
    等你把上面中间的...都写完了,你就知道我在问什么问题了
      

  5.   

    int i = 0;
    foreach (System.Windows.Forms.Control c in this.Controls) //遍历所有控件
    {
       if (c is System.Windows.Forms.TextBox&&c.Name.StartsWith("textbox"))//如果是TextBox控件,并且名字以textbox开头
       {
         (c as TextBox).Text = (c as TextBox).Name.Substring("textbox".Length);
         //把这个控件类型转换成TextBox类型,给它的Text属性赋值,---Substring("textbox".Length);截取textbox123中的123
       }
    }
      

  6.   


    为什么不行 你的控件类型是什么 如果是TextBox  就(FindControl["textbox" + i] as TextBox).text