110,538
社区成员
发帖
与我相关
我的任务
分享
namespace WindowsApplication27
{
public partial class Form1 : Form
{
List<Point> Points = new List<Point>();
Point MovePoint;
public Form1()
{
InitializeComponent();
}
private void Form1_MouseDown(object sender, MouseEventArgs e)
{
if (Points.Count == 0)
{
Points.Add(e.Location);
MovePoint = new Point(e.X, e.Y);
}
else if (Points.Count == 1)
Points.Add(e.Location);
else if (Points.Count == 2)
{
Points.RemoveAt(0);
Points.RemoveAt(0);
}
}
private void Form1_MouseMove(object sender, MouseEventArgs e)
{
if (Points.Count == 1)
MovePoint = new Point(e.X,e.Y);
this.Refresh();
}
private void Form1_Paint(object sender, PaintEventArgs e)
{
if (Points.Count == 1)
e.Graphics.DrawLine(new Pen(new SolidBrush(Color.Red)), Points[0], MovePoint);
else if (Points.Count == 2)
e.Graphics.DrawLine(new Pen(new SolidBrush(Color.Red)), Points[0], Points[1]);
}
}
}