for (int i = 0; i < 10; i++)
{
      TextBox t = new TextBox();
      t.Location = new Point(10 + i * 70, 150);
      t.Name = "txttest" + Convert .ToString (i);
      t.Size = new Size(60,100);
      t.Visible = true;
      t.Parent = this;
      t.ReadOnly = true;
      t.TextAlign = HorizontalAlignment.Center;
      t.BringToFront();
      t.Text = "0";
}
我使用以上代码生成10个TextBox后,需要使用定时器隔一段时间更新一次所有TextBox的内容。请问如何实现?

解决方案 »

  1.   

    建议设置一下这些TextBox的Tag属性,便于记住谁是谁,呵呵。。这样在更新的时候才好对好入座。
    从工具箱拖一个Timer控件到界面,设置Interval属性,即你说的“一段时间”;然后双击Timer控件,VS会自动生成OnTimer事件的处理方法,在该方法中进行更新即可。。
      

  2.   

    定义全局变量数组:
    TextBox[] tbs=new TextBox[10]修改你的循环算法:
    for (int i = 0; i < 10; i++) 

          TextBox t = new TextBox(); 
          t.Location = new Point(10 + i * 70, 150); 
          t.Name = "txttest" + Convert .ToString (i); 
          t.Size = new Size(60,100); 
          t.Visible = true; 
          t.Parent = this; 
          t.ReadOnly = true; 
          t.TextAlign = HorizontalAlignment.Center; 
          t.BringToFront(); 
          t.Text = "0"; 
          tbs[i]=t;
    } 在Timer控件的Tick事件中处理各TextBoxfor(int i=0;i<10;i++)
    {
       tbs[i]="刷新的内容"
    }
      

  3.   

    我想请问下,如果我现在不再本页面Timer还有用吗?