Skip to content

C# X and Y problems of a picture box

shena forga

Asked Sep 12, 2009, 8:08 AM EDT2 answers
Share
LinkedInX
Ok heres the layout:

I have two picture boxs that move around and are meant to bounce off the sides of the form they are on. This is part of the code i have for that:

private void timer1_Tick(object sender, EventArgs e)

{

if (clicked)

{

Point p = bball.Location;

p.X += 1;

p.Y += 1;

bball.Location = p;

Point p2 = rball.Location;

p2.X += 1;

p2.Y += 1;

rball.Location = p2;

}

if (moving)

{

if (bball.Y > bball)

vy = Math.Abs(vy) * -1;

else if (bball.Y vy = Math.Abs(vy);

if (bball.X > bounceright)

vx = Math.Abs(vx) * -1;

else if (bball.X vx = Math.Abs(vx);

}

}

X and Y are throwing lots of errors if "if (moving)". Even if i made a point like the first part of the timer, it says cant be used. bball is a picture box on the form already made. Shouldn't the picture box already have and x and y to it...? I'm having trouble finding what code works for this.

2 Answers

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
    First I think you are trying to compare an integer with an object....

    if (bball.Y > bball)

    bball.y can not be compared to bball the object.

    Normally when I do something like this i would start with x,y direction variables...
    int xDirection=1;
    int yDirection=1;
    int xMin=0;
    int yMin=0;
    int xMax=100;
    int yMax=100;

    bball.x = bball.x + xDirection;
    bball.y = bball.y + yDirection;

    if (bball.x < xMin) {xDirection = 1;}
    if (bball.x > xMax) {xDirection = -1;}
    if (bball.y < yMin) {yDirection = 1;}
    if (bball.y > yMax) {yDirection = -1;}
    0
  • 0
    my only problem with that is that X and Y become errors even though x and y are stated within the picturebox properties
    0