Label Array in VB.net [closed]

末鹿安然 提交于 2019-12-13 10:41:12

问题


I have 10 labels (Label1, Label2, Label3, Label4, etc...) in an Array and I need to change the Text property with a timer, I have the timer working well, but I don't know how to change one Label at the time( this second the label1, the next second label2, the next second label3...etc)...

I'm using VB.NET with the .NET 4.0 Framework in Visual Studio.

Thanks!


回答1:


If you have the timer set up and working already, try something like this for your array:

'These will be your labels:
Dim oLabel As New Label
Dim oLabel2 As New Label

'Create the array from your labels:
Dim aLabels() As Label = {oLabel, oLabel2}

'loop through your array:
For each oLabel as Label in aLabels

  oLabel.Text = "your text value here"

Next



回答2:


You can try with something like this:

Imports System.Windows.Forms

Public Class Form1
Private _labels As Label()

Public Sub New()

    ' This call is required by the designer.
    InitializeComponent()

    ' Add any initialization after the InitializeComponent() call.
    InitalizeLabelArray()
End Sub

Private Sub InitalizeLabelArray()
    _labels = New Windows.Forms.Label() {Label1, Label2, Label3}
End Sub


End Class



回答3:


VB.NET is not VB6 and does not have control arrays.

There are ways to emulate them (adding them to a collection and looping over the collection), or using the Form.Controls collection and only acting on Label controls, for example.



来源:https://stackoverflow.com/questions/6390510/label-array-in-vb-net

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!