VB.NET迭代表单标签 [英] VB.NET Iterating Form Labels
问题描述
我的设计表单上有几个标签框,它们共享命名约定 lbl _#。text
其中#的范围从1到60.我想要一个循环迭代遍历每个 lbl _#。text
增加一些增量值,比方说这个问题的理论目的为2的倍数。
最终的结果将如下所示:
lbl_1.text =2
lbl_2。 text =4
lbl_3.text =6
...
lbl_60.text =120
我不知道如何通过编码来访问每个标签,我只知道如何明确提及每个标签并赋值:/ /
使用Controls集合:
类Form1
Private Sub Form1_Load(ByVal sender As System.Object,ByVal e As System.EventArgs)处理MyBase.Load
Dim i As Integer
For i = 1 T o 3
Dim myLabel As Label = CType(Me.Controls(lbl_& i),Label)
myLabel.Text = ...你想要放在这里的任何值
Next
End Sub
End Class
I have several label boxes on my design form that all share the naming convention lbl_#.text
where # ranges from 1 to 60. I want to make a loop that iterates through each lbl_#.text
adding some incremental value, let's say multiples of 2 for this question's theoretical purpose.
Something such that the end result would amount to the following:
lbl_1.text = "2"
lbl_2.text = "4"
lbl_3.text = "6"
...
lbl_60.text = "120"
I'm not sure how to access each of these labels through the coding side, I only know how to explicitly mention each label and assign a value :/
Use the Controls collection:
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim i As Integer
For i = 1 To 3
Dim myLabel As Label = CType(Me.Controls("lbl_" & i), Label)
myLabel.Text = ...whatever value you want to put here
Next
End Sub
End Class
这篇关于VB.NET迭代表单标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!