now to get the coordinates on the line joining A & B, you need to use little line formula and find out the coordinates....

I can post that too, if you want...but hope you know it if you have studied geometry in school days!! (no offense here!!!)

Solved

Posted on 2007-09-29

I have a picture box pict and two point A and B.

I want picture box move on the line connect two point A and B.

How to make this?

Thanks

I want picture box move on the line connect two point A and B.

How to make this?

Thanks

4 Comments

now to get the coordinates on the line joining A & B, you need to use little line formula and find out the coordinates....

I can post that too, if you want...but hope you know it if you have studied geometry in school days!! (no offense here!!!)

// Add these Class members

private Point startLocation = new Point( 0, 0); // Initialize to desired start

private Point endLocation = new Point( 10, 10); // Initialize to desired end

private int stepCount = 10; // Initialize to desired number of steps

private int steps = 0; // This is the number of times we have moved the control

This is the event handler for the timer:

private void timer_Tick(object sender, EventArgs e)

{

steps += 1;

if (steps >= stepCount) // Done

{

// yourTimer.Dispose();

return;

}

double ratio = (double)steps / (double)stepCount;

int newX = startLocation.X + (int)((double)(endLocation

int newY = startLocation.Y + (int)((double)(endLocation

Point current = new Point(newX, newY);

myPictureBox.Location = current;

}

Jim

Do you want:

(1) A fixed number of "jumps" between the points? (this is what JimBrandley has done) Your picturebox would always take the same amount of time to travel the distance between "A" and "B" irregardless of the distance between them...whether it be 50 pixels or 1000 pixels.

(2) A fixed rate of travel between the points? Here you would need to calculate the amount of time it would take to travel the distance and then either adjust your timer accordingly (for a fixed number of jumps), or calculate the "percentage" or the time currently transpired and determine the location that corresponds to that "time".

By clicking you are agreeing to Experts Exchange's Terms of Use.

Title | # Comments | Views | Activity |
---|---|---|---|

Contant UI messages in .NET | 1 | 17 | |

On screen keyboard. | 3 | 35 | |

ASP.NET C# System.Threading.Thread.Sl |
10 | 37 | |

asp.net c# read lines of text file and put each row in mutliple variables variables not updated | 3 | 28 |

Join the community of 500,000 technology professionals and ask your questions.

Connect with top rated Experts

**8** Experts available now in Live!