I am trying to create an animation of shapes created by 5 or more picture boxes moving together. The shape supposed to move from one place to another. In its way there are more picture boxes. The form has a picture background. The code I used for this is the following:
//caculating image path
double slope = (double)(474 + 30 * squareRow - originalBoard.Location.Y) / (originalBoard.Location.X - 41 + 30 * squareCol);
int dis = originalBoard.Location.X - animArr[originalButton].Location.X;
counter = 1;
while (counter != dis)
{
for (int k = 0; k < animArr.Length; k++)
{
//creating new point
Point xy = new Point(pointArr[k].X + counter, pointArr[k].Y - (int)Math.Ceiling(slope * (double)counter));
animArr[k].Location = xy;
//updating image
animArr[k].Update();
this.Update();
}
if (counter + 3 > dis)
counter = dis;
else
counter+=3;
}
the code has 2 issues: The shape moving extremely slow, especially when hovering over a picture box or a label. In addition, after it reaches it's destination, the form is freezing.
does anyone know why it happens and how to fix it?