# using System using System Collections Generic using System ComponentMo

 ``` 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90``` ```using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace WindowsFormsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { } static Point P1 = new Point(152, 140); static Point P2 = new Point(260, 60); static PointF p1 = new PointF(1, 1); static PointF p2 = new PointF(1, 1); private void Form1_Paint(object sender, PaintEventArgs e) { float t2 = (float) Math.Sqrt((P2.X - P1.X) * (P2.X - P1.X) + (P2.Y - P1.Y) * (P2.Y - P1.Y)); PointF[] output = new PointF[(int)(t2) + 1]; for (float t = 0; t < t2; t += 1f) { float X = P1.X + p1.X * t + (3 * (P2.X - P1.X) / t2 / t2 - 2 * p1.X / t2 - p2.X / t2) * t * t + (2 * (P1.X - P2.X) / t2 / t2 / t2 + p1.X / t2 / t2 + p2.X / t2 / t2) * t * t * t; float Y = P1.Y + p1.Y * t + (3 * (P2.Y - P1.Y) / t2 / t2 - 2 * p1.Y / t2 - p2.Y / t2) * t * t + (2 * (P1.Y - P2.Y) / t2 / t2 / t2 + p1.Y / t2 / t2 + p2.Y / t2 / t2) * t * t * t; output[(int)(t)] = new PointF(X, Y); } Graphics g = e.Graphics; g.DrawLines(new Pen(Color.Black), output); g.DrawEllipse(new Pen(Color.Black), P1.X - 5, P1.Y - 5, 10, 10); g.DrawEllipse(new Pen(Color.Black), P2.X - 5, P2.Y - 5, 10, 10); } private bool isDragging = false; private int id = -1; private void Form1_MouseDown(object sender, MouseEventArgs e) { if (Math.Abs(P1.X - e.X) < 10 && Math.Abs(P1.Y - e.Y) < 10) { id = 0; this.isDragging = true; } else if (Math.Abs(P2.X - e.X) < 10 && Math.Abs(P2.Y - e.Y) < 10) { id = 1; this.isDragging = true; } } private void Form1_MouseUp(object sender, MouseEventArgs e) { id = -1; this.isDragging = false; } private void Form1_MouseMove(object sender, MouseEventArgs e) { if (id == 0) { P1.X = e.X; P1.Y = e.Y; } else if (id == 1) { P2.X = e.X; P2.Y = e.Y; } this.Invalidate(); } } } ```