question

samhobbs avatar image
0 Votes"
samhobbs asked samhobbs commented

How to move a PictureBox back to the original starting location?

I am currently working on a game right now, which involves a ball (PictureBox), a paddle, some blocks and borders. The game board contains 4 borders: a top border, a left border, a right border, and a bottom border. The bottom border is the part that I am meant to focus on. Basically, when my ball touches the bottom border, it will freeze. The idea behind it is that the ball will freeze for a few seconds and then it will go back to the ball's original starting location. However, so far, I have unfortunately been unable to find a way of doing this. I have tried using Ball.Location (Ball is the name of the PictureBox), and then putting the ball's starting coordinates in brackets, however, I am getting this error:

BC30311 Value of type '(Integer, Integer)' cannot be converted to 'Point'.

Here is a snippet of the area of code which is causing the issue:

145803-code.png



The first 3 lines are fine, it is the 4th line which is causing me issues. The 'Ball.Location' part seems to be fine, but when I input the values into the brackets, I get an error. I'm assuming that I would need to convert the values to 'Point' type instead of Integer, but I don't know how to do it.

(I should also mention that both the ball AND border are PictureBoxes).

dotnet-visual-basic
code.png (4.7 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Viorel-1 avatar image
1 Vote"
Viorel-1 answered samhobbs commented

Try Ball.Location = new Point( 266, 338 ).


· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

That worked! Thank you so much!!

0 Votes 0 ·
XingyuZhao-MSFT avatar image
0 Votes"
XingyuZhao-MSFT answered

Hi @GG01Coding-3690 ,
You can define a point to record the original starting location of the ball,

     Dim oriPoint As New Point
     oriPoint=Ball.Location

Every time you want to move a PictureBox back to the original starting location, just:

     Ball.Location = oriPoint

Best Regards,
Xingyu Zhao


If the answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.