VB操纵面板内的大量标签

时间:2013-12-26 10:45:29

标签: vb.net panel labels

所以我有一个面板内的100个标签,我需要更改他们的文本。我尝试过,我尝试像数组一样没有成功的Tab Index,任何想法我如何选择和更改这些标签的属性?< / p>

Sub setCartela(ByVal numeros As Integer)
    For cont As Integer = 0 To numeros Step 1
//change labels text inside panel
    Next
End Sub

2 个答案:

答案 0 :(得分:1)

试试这个......

Dim i as Integer = 1
For Each ctrl As Control In Panel1.Controls
        If ctrl.GetType.ToString = "System.Windows.Forms.Label" Then
            ctrl.Text = "Text" & format(i)
        End If
        i += 1
Next

答案 1 :(得分:0)

试试这段代码:

dim _countLbl as integer = 1 
For each Lbl as Label in Panel1.Controls.Oftype(Of Label)()

Lbl.text="Label" & _countLbl    
_countLbl += 1

Next