Creating an array of pictureboxes and moving them left and right without going off the page.

  • Thread starter Thread starter J0J0T5
  • Start date Start date
J

J0J0T5

Guest
I'm really struggling to make an array of picture boxes and moving them all at the same time, at runtime but it doesn't seem to work so I have tried moving the individually but they move one after the other.

This is the code that I have tried.

Dim movekron As Integer = 6
Dim oppositeDirection As Integer = -1

Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
PlayerMovement()
If PictureBox1.Location.X = Me.Width - PictureBox1.Width Then
movekron = movekron * oppositeDirection
ElseIf PictureBox1.Location.X < 0 Then
movekron = movekron * oppositeDirection
End If
End Sub

Private Sub PlayerMovement()
#Region "MOVE KRONS"
PictureBox1.Location = New Point(PictureBox1.Location.X + movekron, PictureBox1.Location.Y)
PictureBox2.Location = New Point(PictureBox2.Location.X + movekron, PictureBox2.Location.Y)
PictureBox3.Location = New Point(PictureBox3.Location.X + movekron, PictureBox3.Location.Y)
PictureBox4.Location = New Point(PictureBox4.Location.X + movekron, PictureBox4.Location.Y)
PictureBox5.Location = New Point(PictureBox5.Location.X + movekron, PictureBox5.Location.Y)
PictureBox6.Location = New Point(PictureBox6.Location.X + movekron, PictureBox6.Location.Y)
PictureBox7.Location = New Point(PictureBox7.Location.X + movekron, PictureBox7.Location.Y)
PictureBox8.Location = New Point(PictureBox8.Location.X + movekron, PictureBox8.Location.Y)
PictureBox9.Location = New Point(PictureBox9.Location.X + movekron, PictureBox9.Location.Y)
PictureBox10.Location = New Point(PictureBox10.Location.X + movekron, PictureBox10.Location.Y)
PictureBox11.Location = New Point(PictureBox11.Location.X + movekron, PictureBox11.Location.Y)
PictureBox12.Location = New Point(PictureBox12.Location.X + movekron, PictureBox12.Location.Y)
PictureBox13.Location = New Point(PictureBox13.Location.X + movekron, PictureBox13.Location.Y)
PictureBox14.Location = New Point(PictureBox14.Location.X + movekron, PictureBox14.Location.Y)
PictureBox15.Location = New Point(PictureBox15.Location.X + movekron, PictureBox15.Location.Y)
PictureBox16.Location = New Point(PictureBox16.Location.X + movekron, PictureBox16.Location.Y)
PictureBox17.Location = New Point(PictureBox17.Location.X + movekron, PictureBox17.Location.Y)
PictureBox18.Location = New Point(PictureBox18.Location.X + movekron, PictureBox18.Location.Y)
PictureBox19.Location = New Point(PictureBox19.Location.X + movekron, PictureBox19.Location.Y)
PictureBox20.Location = New Point(PictureBox20.Location.X + movekron, PictureBox20.Location.Y)
PictureBox21.Location = New Point(PictureBox21.Location.X + movekron, PictureBox21.Location.Y)
PictureBox22.Location = New Point(PictureBox22.Location.X + movekron, PictureBox22.Location.Y)
#End Region
End Sub

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.FormBorderStyle = Windows.Forms.FormBorderStyle.None
Me.WindowState = FormWindowState.Maximized
Timer1.Start()
#Region "KRONSTARTINGPOINTS"
PictureBox1.Location = New Point(179, 38) ''
PictureBox2.Location = New Point(285, 38)
PictureBox3.Location = New Point(391, 38)
PictureBox4.Location = New Point(497, 38)
PictureBox5.Location = New Point(603, 38)
PictureBox6.Location = New Point(709, 38)
PictureBox7.Location = New Point(815, 38)
PictureBox8.Location = New Point(921, 38)
PictureBox9.Location = New Point(1027, 38)
PictureBox10.Location = New Point(1133, 38)
PictureBox11.Location = New Point(1239, 38)
PictureBox12.Location = New Point(179, 150) ''
PictureBox13.Location = New Point(285, 150)
PictureBox14.Location = New Point(391, 150)
PictureBox15.Location = New Point(497, 150)
PictureBox16.Location = New Point(603, 150)
PictureBox17.Location = New Point(709, 150)
PictureBox18.Location = New Point(815, 150)
PictureBox19.Location = New Point(921, 150)
PictureBox20.Location = New Point(1027, 150)
PictureBox21.Location = New Point(1133, 150)
PictureBox22.Location = New Point(1239, 150)
#End Region
End Sub
End Class

I was able to move a 3 <g class="gr_ gr_322 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling ins-del multiReplace" data-gr-id="322" id="322">picturebox</g> back and forth but when I try adding move it starts lagging

Public Class Form1
Dim movekron As Integer = 1.5
Dim oppositeDirection As Integer = -1

Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
PlayerMovement()
If PictureBox1.Location.X = Me.Width - PictureBox1.Width Then
movekron = movekron * oppositeDirection
ElseIf PictureBox1.Location.X < 0 Then
movekron = movekron * oppositeDirection
End If
PictureBox1.Location = New Point(PictureBox1.Location.X + movekron, PictureBox1.Location.Y)
End Sub
Private Sub PlayerMovement()
PictureBox1.Location = New Point(PictureBox1.Location.X + movekron, PictureBox1.Location.Y)
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Timer1.Start()
End Sub
End Class


Could <g class="gr_ gr_450 gr-alert gr_tiny gr_spell gr_inline_cards gr_run_anim ContextualSpelling multiReplace" data-gr-id="450" id="450">i</g> please have some help. I would really appreciate it.

Thank you

Continue reading...
 
Back
Top