PDA

View Full Version : Shapes and Moving PictureBox's



Footy
10-13-2012, 08:30 PM
Hey, I'm working on my first VB Program, but I can't figure a couple things out:

1) Is there a way to create shapes like in lazarus?

2) I ended up settling for a Picturebox, how do I move a picturebox? I tried

PictureBox1.Location.Y = PictureBox1.Location.Y + 5
But that gave this error:
Expression is a value and therefore cannot be the target of an assignment.

I also tried this:

PictureBox1.Location.Offset(5, 5)
That compiled, but it didn't do anything. Any help is appreciated!

Thanks guys
~Not Handy

Brandon
10-13-2012, 10:32 PM
PictureBox1.Location = new Drawing.Point(x, y)

Footy
10-13-2012, 10:50 PM
Whoops, I should have closed this, I found a solution. I used the += and -= operators like this:

PictureBox1.Top -= 10

But that brings me to another question. I'm trying to make a bouncing ball on my form, but its acting really strangly. Every run, the ball acts differently, it bounces in different ways, stuff like that. Am I doing something wrong? This is my Timer_Tick code.


Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
If PictureBox1.Top <= Me.Top Then
UpOrDown = False

End If

If PictureBox1.Top + PictureBox1.Height >= Me.Height Then
UpOrDown = True

End If

If PictureBox1.Left <= Me.Left Then
LeftOrRight = False

End If

If PictureBox1.Left + PictureBox1.Width >= Me.Width Then
LeftOrRight = True

End If

If UpOrDown = True Then
PictureBox1.Top -= 10
Else
PictureBox1.Top += 10
End If

If LeftOrRight = True Then
PictureBox1.Left -= 10
Else
PictureBox1.Left += 10

End If
End Sub

Thanks for the help Brandon and whoever answers this question, :)

E: Sorry for the lack of info, but It's hard to describe whats happening. I can send someone the .exe if they want to see whats happening. Basically, every time I run the program, the ball bounces at different spots. The "celing" it hits at the top and the "floor" it hits on the bottom are different, same with the "walls". Any Ideas?

Footy