以编程方式在列中添加标签

Add labels programmatically in a column

这是我的代码。它不起作用。标签不会出现。我一直找不到我的错误。

 For i = 0 To 408 Step 51
        Dim text As Integer = 0
        Dim label as New Label
        Dim name As String = "lbl" + CStr(i)

        With label
            .Location = New Point(49, 33 + i)
            .Size = New Size(32, 32)
            .Name = name
            .Font = New Font("Microsoft Sans Serif", FontStyle.Bold)
            .Text = CStr(text)
            .Visible = True
        End With

        Me.Controls.Add(label)
        text += 1
    Next

有人能指出来吗?

将创建字体的行更改为

.Font = New Font("Microsoft Sans Serif", 12, FontStyle.Bold)

指定尺寸,否则默认为尺寸 1。不太明显。
另请注意,您在每个循环中将 text 变量设置为零,因此所有控件都具有相同的文本。