private double GetAngle(double x1,double y1,double x2,double y2)
{
double ang = Math.Atan((x1 - x2) / (y1 - y2)) * Rad2Deg;
if ((x1 < x2) && (y1 > y2))
return ang;
else if (((x1 < x2) && (y1 < y2)) || ((x1 > x2) && (y1 < y2)))
return ang + 180d;
else
return ang + 360d;
}
public void MoveTo(double x, double y)
{
TX = x; TY = y;
Angle = GetAngle(TX, TY, X, Y);
TimerMove.Interval = 10;
TimerMove.Start();
}
private void Move(object sender, EventArgs e)
{
X += Speed * (Math.Sin(Angle * Rad2Deg));
Y += Speed * (Math.Cos(Angle * Rad2Deg));
}
TimerMove.Interval = 10;
TimerMove.Start();