如何更改循环中所有标签的值

时间:2015-01-28 15:16:39

标签: vb.net loops text label

我试图将标签的值更改为位于数组中的某个值。我有一个遍历我的数组的循环

我希望能够做到这样的事情

标签& i.text ="一些文字"

Dim QuestionArray(10) As String
'dr is OleDbDataReader from database
While dr.Read()
QuestionArray(cnt)=(dr("Question").ToString)
cnt+=1
End While

For i = 0 To QuestionArray.Length
'Label(i) can not be used
Label(i).text = QuestionArray(i)
Next i 

2 个答案:

答案 0 :(得分:1)

我希望它可以帮助你...

For Each objCtrl As Control In yourFormName.Controls
        ' Assign Some Text 
If TypeOf objCtrl Is Label Then
End If
Next

答案 1 :(得分:1)

您可以创建一个数组来保存标签。

Dim LabelArray() As Label = {Label0, Label1, Label2, Label3, Label4, Label5, _
  Label6, Label7, Label8, Label9, Label10}
    For i = 0 To QuestionArray.Length - 1
        LabelArray(i).Text = QuestionArray(i)
    Next