我有一个KeyValuePair
的列表,其中KeyValuePair
的数量随时间而变化。在表单中,我需要为包含KeyValuePair
作为文本的每个Value
创建一个标签。
我该怎么做?
这是我试过的......
For Each element In keyvalueP
Dim Label1 As New Label
With Label1
.Width = 512
.Height = 18
.Left = 12
.Text = " Nr. " & i & " - Matchtype " & element.Value.ToString
End With
i = i + 1
Next
答案 0 :(得分:0)
我实际上设法找到一个有效的解决方案
Private Sub R75Dialog_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim labelText = ""
Dim i = 0
For Each element In keyvalueP
labelText = " Nr. " & i & " Groupname: " & element.Key.ToString & " - Matchtype " & element.Value.ToString
Dim label As New Label()
Dim count As Integer = Panel1.Controls.OfType(Of Label)().ToList().Count
label.Location = New Point(10, (25 * count) + 2)
label.Size = New Size(1000, 20)
label.Name = "label_" & (count + 1)
label.Text = labelText
Panel1.Controls.Add(label)
i = i + 1
Next
End Sub