VB.net 中的标签数组

发布于 2024-11-15 18:13:27 字数 218 浏览 5 评论 0原文

我在 Array 中有 10 个标签(Label1、Label2、Label3、Label4 等),我需要用计时器更改 Text 属性,我有计时器运行良好,但我不知道如何更改当时的一个标签(这一秒标签1,下一秒标签2,下一秒标签3...等)...

我正在使用VB.NET与Visual Studio 中的 .NET 4.0 框架。

谢谢!

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

任谁 2024-11-22 18:13:27

你可以尝试这样的事情:

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

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
还在原地等你 2024-11-22 18:13:27

如果您已设置计时器并已开始工作,请为您的阵列尝试以下操作:

'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

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
我不会写诗 2024-11-22 18:13:27

VB.NET 不是 VB6,并且没有控件数组

有多种方法可以模拟它们(将它们添加到集合中并循环遍历集合),或使用 Form.Controls 集合,仅作用于 Label 控件。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文