1.如窗體中有textbox1,textbox2,textbox3....textboxN 
現在我想這樣做: 
dim   inti   as   integer 
for   inti=1   to   n 
      textbox   &   n.text= " " 
next 
我就怎樣通過變量名來方問控件. 
2.如窗體中有textbox1,textbox2,textbox3....textboxN 
現在我想通過遍歷某類控件來方問窗體的控件,就如何做.                               
      Dim   ctl   As   Control 
      For   Each   ctl   In   Me.Controls 
            If   TypeOf   ctl   Is   TextBox   Then   ctl.Text   =   " " 
      Next 
我這樣做是實現了想要的功能,但我主管說我把所有的控件都遍歷了一次,有沒有什么辦讓我只遍歷某一類控件,如TEXTBOX

解决方案 »

  1.   

    你的方法不行吗?
    c#
    foreache(Control s in Contorls)
    {
      if(s.typeof()==textboxt1.typeof())
       {
          messagebox.show(s.id);
       }
      

  2.   


    foreache(Control   s   in   Contorls) 

        if(s.typeof()==textboxt1.typeof()) 
    }
    就是這個循環有問題,選取所有窗體的控件,後在判斷是不是textbox,主管說效率太低。
    現在要求只取全部的textbox來做判斷。
      

  3.   


    ArrayList al = new ArrayList();
    for (int i = 1; i < 10; i++)
    {
       al.Add("textBox" + i.ToString());                
    }
    for(int i =0;i<al.Count;i++)
    {
      ((TextBox)(this.Controls[al[i].ToString()])).Text = "test";
    }
      

  4.   

    你把所有textbox放到panel里,然后对panel的Controls属性遍历
    foreache(Control   s    in       panel1.Contorls)   
    {   
            if(s.typeof()==textboxt1.typeof())   
      

  5.   

    小高的方法是減少了些,但還有有大量的其它控被包含在panel了.
    用控件數組的話,位置不是很好定.