嘿,我正在为我的表单创建一些运行时标签:
Dim tmpLbl As New Label
Dim intX As Integer = 0
Do Until intX = 4
With tmpLbl
.Size() = New System.Drawing.Size(58, 15)
.Text = "Run-time Controls " & intX
.Location = New System.Drawing.Point(2, 20)
.Name = "test" & intX
End With
With Me.Controls
.Add(tmpLbl)
End With
intX += 1
Loop
这工作得很好......但是当我想要时,说在表单上放置一个按钮,调用这些运行时控件之一,如下所示:
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Debug.Print(tmpLbl.Name)
End Sub
当然,上面的这个是行不通的。当我单击该按钮时,如何获取标签名称(例如:test2)并阅读其文本(例如:运行时控件 2 )?