Reputation: 11
I've been trying to create a code to simulate a queue for something(haven't got to that yet) for school and am trying to create multiple picture boxes and store them in a list. For some reason they are not appearing...anyone got any suggestions?
Public Class Form1 Dim peoples As New List(Of PictureBox)() Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load Timer1.Enabled = True Timer1.Interval = randomnumber(100, 500) End Sub Sub loopover() Timer1.Interval = randomnumber(100, 500) End Sub Function randomnumber(lower As Integer, upper As Integer) Randomize() Return Int((upper * Rnd()) + lower) End Function Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick loopover() newqueuemember() End Sub Private Sub newqueuemember() Dim pictureBox As New PictureBox pictureBox.Width = 50 pictureBox.Visible = True pictureBox.Height = 50 Dim selectperson As Integer = randomnumber(1, 3) If selectperson = 1 Then pictureBox.Image = My.Resources.person1 ElseIf selectperson = 2 Then pictureBox.Image = My.Resources.person2 Else pictureBox.Image = My.Resources.person3 End If pictureBox.Location = New Point(10, 20) peoples.Add(pictureBox) End Sub End Class
Upvotes: 0
Views: 920
Reputation: 39
Use a flow layout panel, Define the size (width, height) of the objects, then simply add them to the flow layout panel, you can even have a scrollbar if the length of the list of picture boxes is longer than the height of the panel.
FlowLayoutPanel1.controls.add(picturebox_object)
Upvotes: 0
Reputation: 4283
Under:
peoples.Add(pictureBox)
add:
Me.Controls.Add(pictureBox)
Here's a C# reference (easily translated to VB):
Upvotes: 0