Lawrence Spicher
Lawrence Spicher

Reputation: 1

how do I make a picture box go down in vb

I've updated the code and now it says that index was outside of the bounds of the array and also I'm in cs1 in high school, and accidentally made this account using my school google account. I have included the code specific to moving the bricks down (by just a little), the code for the array, and the code for the entire timer block which as you can see is very organized with regions

Dim newbrickx, newbricky As Integer
newbrickx = bricks(i).Location.X
newbricky = bricks(i).Location.Y + 10
        'left wall
        If (lblball.Location.X >= Me.ClientSize.Width - lblball.Width) Then
            bricks(i).Location = New Point(newbrickx, newbricky)
        End If
        'right wall
        If (lblball.Location.X = 0) Then
            bricks(i).Location = New Point(newbrickx, newbricky)
        End If

the array (in the form load event)

  Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        bricks = New PictureBox() {PictureBox1, PictureBox2, PictureBox3, PictureBox4, PictureBox5, PictureBox6, PictureBox7, PictureBox8}
  End Sub

Upvotes: 0

Views: 79

Answers (1)

meridas
meridas

Reputation: 73

I don't have the reputation to write comments yet, so I do it this way. I assume bricks is an array containing your pictureboxes. So, inside the conditional block you can assign the new position like this:

  bricks(i).Location = New Point(newbrickx, newbricky)

And as commented before you should probably also check for the y coordinates to make sure it is not out of bounds.

Upvotes: 1

Related Questions