0

我想通过单击按钮向表单添加标签。当我在这里使用代码时,它只添加了 1 个标签,但我想添加无限量。每次单击按钮时,即使更改名称,它也只会添加 1 个标签。

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e  As System.EventArgs) Handles Button1.Click

    Dim lbl As New label
    lbl.Size = New System.Drawing.Size(159, 23) 'set your size
    lbl.Location = New System.Drawing.Point(12, 180) 'set your location
    lbl.Text = (TextBox1.Text) 'set your name
    Me.Controls.Add(lbl)  'add your new control to your forms control collection

End Sub
4

2 回答 2

3

像这样的东西:

Dim lbl As New label
lbl.Size = New System.Drawing.Size(159, 23) 'set your size (if required)
lbl.Location = New System.Drawing.Point(12, 180) 'set your location
lbl.Text = "label text goes here" 'set the text for your label
Me.Controls.Add(lbl)  'add your new control to your forms control collection

我会让你以编程方式设置位置。您可以使用诸如全局变量之类的东西来计算已创建的标签数量...

于 2013-10-11T10:03:39.387 回答
1

为列表框中的每个项目添加一个新的链接标签我每次创建一个新的链接标签时将 24 添加到 updown 整数,因此我的链接标签最终位于不同的位置。

将左右调暗为整数 =1018
上下调暗为整数= 56

将 LLCount 调暗为整数

 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Do
     Dim lklabel As New LinkLabel
     lklabel.Size = New System.Drawing.Size(65, 13)
     lklabel.Location = New System.Drawing.Point(rightleft, updown)
     lklabel.Text = ListBox1.Items(LLCount)
     lklabel.Name = "lklabel" & LLCount
     Me.Controls.Add(lklabel)
     updown += 24
     LLCount += 1
     Loop Until lnklbl = ListBox1.Items.Count
  end sub
于 2021-03-27T00:49:46.640 回答