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

samhobbs 41 Reputation points
2021-11-02T13:18:09.967+00:00

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).

VB
VB
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,542 questions
0 comments No comments
{count} votes

Accepted answer
  1. Viorel 110.8K Reputation points
    2021-11-02T14:02:41.407+00:00

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

    1 person found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. Xingyu Zhao-MSFT 5,356 Reputation points
    2021-11-03T02:05:04.307+00:00

    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.

    0 comments No comments