You must add a timer and a button to the form in advance.
Private void button#click (Object sender, eventargs e) <br/>{< br/> timer1.enabled = true; <br/>}</P> <p> private point pt1 = new point (10, 10 ); // start coordinate <br/> private point pt2 = new point (300,300); // end coordinate </P> <p> private int n = 0; // distance from the start point of the motion point <br/> private bool bdirect = true; // true indicates that the operation starts from the start point to the end point, false: run from the end point to the start point <br/> point Pt = new point (0, 0); // current point </P> <p> private void timerspontick (Object sender, even Targs e) <br/>{< br/> // Cartesian triangle, used to calculate the length of the Oblique Edge <br/> int M = (INT) math. pow (math. pow (pt2.x-pt1.x), 2) + math. pow (pt2.y-pt1.y), 2), 0.5); // total distance </P> <p> // judge round-trip <br/> If (n> = m) <br/> bdirect = false; <br/> If (n = 0) <br/> bdirect = true; </P> <p> // Based on round-trip, set addition and subtraction <br/> If (bdirect) <br/> N + = 3; <br/> else <br/> N-= 3; </P> <p> pen p1 = new pen (color. yellow); <br/> pen P2 = new pen (color. red); <br/> graphics g = This. creategraphics (); </P> <p> If (Pt. X! = 0 & pt. y! = 0) // clear the last motion point <br/>{< br/> G. drawellipse (new pen (this. backcolor), PT. x-2, PT. y-2, 1, 1); // clear the last motion point <br/>}</P> <p> G. drawline (P1, pt1, pt2); // draw the line from the start point to the end point </P> <p> PT. X = (pt2.x-pt1.x) * N)/m + pt1.x; <br/> PT. y = (pt2.y-pt1.y) * N/m + pt1.y; </P> <p> G. drawellipse (P2, PT. x-2, PT. y-2, 1, 1); // point of draw motion <br/> G. dispose (); <br/>}< br/>