0

我想出了如何根据添加到列表框中的项目数向我的表单添加控件。

    ListBox1.Items.Add(TextBox1.Text)
    TextBox1.Text = ""

    For i As Integer = 0 To ListBox1.Items.Count - 1

        'adds picturebox for as many listbox items added
        Dim MyPictureBox As New PictureBox()
        MyPictureBox.Location = New Point(25, 25)
        MyPictureBox.Size = New Size(15, 15)
        MyPictureBox.SizeMode = PictureBoxSizeMode.StretchImage
        Me.Controls.Add(MyPictureBox)
        MyPictureBox.Image = My.Resources.PDF_Info

    Next i

我似乎无法弄清楚如何添加第二个控件,但将其添加到表单的另一个位置。

所以第一个条目会将图片框放在 25、25 处,当我输入第二个项目时,它将在 45、45 等处创建另一个图片框。

这可以做到吗?

4

2 回答 2

1
  ListBox1.Items.Add(TextBox1.Text)
TextBox1.Text = ""
Dim x As Integer = 25
For i As Integer = 0 To ListBox1.Items.Count - 1

    'adds picturebox for as many listbox items added
    Dim MyPictureBox As New PictureBox()
    MyPictureBox.Location = New Point(x, x)
    MyPictureBox.Size = New Size(15, 15)
    MyPictureBox.SizeMode = PictureBoxSizeMode.StretchImage
    Me.Controls.Add(MyPictureBox)
    MyPictureBox.Image = My.Resources.PDF_Info
    x += 25
Next i
于 2012-09-14T03:04:07.627 回答
1

会是这样的

ListBox1.Items.Add(TextBox1.Text)
TextBox1.Text = ""
Dim p as Integer = 25

For i As Integer = 0 To ListBox1.Items.Count - 1
    'adds picturebox for as many listbox items added
    Dim MyPictureBox As New PictureBox()
    MyPictureBox.Location = New Point(p , p)
    MyPictureBox.Size = New Size(15, 15)
    MyPictureBox.SizeMode = PictureBoxSizeMode.StretchImage
    Me.Controls.Add(MyPictureBox)
    MyPictureBox.Image = My.Resources.PDF_Info
   'add 20  to the current position of the control
   p = p + 20

Next i
于 2012-09-14T03:05:50.560 回答