在 vb.net 中以编程方式将多个图片框添加到表单?

Adding multiple pictureboxes to a form programmatically in vb.net ?

我必须按照我的要求将图片框添加到面板中。

"Adding multiple pictureboxes to a form programmatically in vb.net " 在这个问题中 PictureBox 是随机绘制的,但我希望它以同步方式绘制 在此处输入代码

Dim i As String = ListBox1.Items.Count
For j As Integer = 0 To i
Dim PicBox As New PictureBox
PicBox.Width = 40
PicBox.Top = 25
PicBox.Left = j + 15
PicBox.SizeMode = PictureBoxSizeMode.StretchImage
PicBox.BorderStyle = BorderStyle.FixedSingle
Me.Panel1.Controls.Add(PicBox)
Next

我想使用自动检查 i 值的计数器?

有什么想法或建议吗?

谢谢

这样的事情怎么样:

Private Sub PicBoxTestButton_Click(sender As System.Object, e As System.EventArgs) Handles PicBoxTestButton.Click
    Try
        Dim numberOfPics As Integer = ListBox1.Items.Count
        Dim lastLeft As Integer = 15
        Const spacer As Integer = 5
        For parser As Integer = 0 To numberOfPics
            Dim PicBox As New PictureBox
            PicBox.Width = 40
            PicBox.Top = 25
            PicBox.Left = lastLeft
            lastLeft = PicBox.Width + PicBox.Left + spacer
            PicBox.SizeMode = PictureBoxSizeMode.StretchImage
            PicBox.BorderStyle = BorderStyle.FixedSingle
            Me.Panel2.Controls.Add(PicBox)
        Next
    Catch ex As Exception
        MessageBox.Show(String.Concat("An error occurred: ", ex.Message))
    End Try
End Sub