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
PictureBoxes
alright, but where in that code are you actually adding them to the form? Hint: nowhere. – jmcilhinney.Location
property accordingly. Alternatively, you can add them to either a TabeLayoutPanel, or possibly a FlowLayoutPanel which would take care of arranging them for you:FlowLayoutPanel1.Controls.Add(pictureBox)
. – Idle_MindPrivate Rnd As New Random
Then use like thisTimer1.Interval = Rnd.Next(100, 500)
Which will return a random number from 100 to 499. – Mary