Hi NewGuy
Hope you had a good Christmas break. Not sure if you are still looking at this post but if you are (or anybody else is), would you know why the following code is only moving one box as supposed to all the picturebox controls on the form. I have 2 versions of the code based on your recommendation. Version B moves all boxes (but i would rather not use the if..then clause) and Version A only moves one box ie pic1.
See below
Version A
Code:
Public Class Form1
'Dim MyPics As Array = New PictureBox() {pic1, pic2, pic3, pic4, pic5, pic6}
Dim mypic As New List(Of PictureBox)
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If Timer1.Enabled = False Then
Timer1.Enabled = True
Timer1.Interval = 500
Else
Timer1.Enabled = False
End If
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
mypic.AddRange(New PictureBox() {pic1, pic2, pic3, pic4, pic5, pic6})
Static a As Integer = 10
Dim b As Integer = 593
For Each pb As PictureBox In mypic
While a < b
pb.Top = a
a += 10
Exit Sub
End While
Next
a = Nothing
End Sub
End Class Version B
Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If Timer1.Enabled = False Then
Timer1.Enabled = True
Timer1.Interval = 500
Else
Timer1.Enabled = False
End If
''pic1.Top = 10
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Dim mypics As New List(Of PictureBox)
Static a As Integer
Dim b As Integer = 10
mypics.AddRange(New PictureBox() {pic1, pic2, pic3, pic4, pic5, pic6})
For Each pb As PictureBox In mypics
If pb.Bottom < 539 Then
pb.Top = a
a += 2
Else
pb.Top = 10
a = Nothing
pb.Top = a
a += 2
Exit Sub
End If
Next
End Sub
Bookmarks