问题
i have to add pictueboxes in to a panel as per my requirement .
"Adding multiple pictureboxes to a form programmatically in vb.net " In this question PictureBox are drawn in random but i want it in a synchronous way enter code here
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 want to use counter which automatically check the value of i ?
Any idea or suggestion ?
Thank you
回答1:
How about something like this:
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
来源:https://stackoverflow.com/questions/31244018/adding-multiple-pictureboxes-to-a-form-programmatically-in-vb-net