c#编写一个Line Length应用程序

编写一个Line Length应用程序。
在窗体上绘制一条黑色直线并计算他的长度。该直线从按下鼠标按钮出的坐标开始,直到释放鼠标按钮的那点结束。应用程序应当在“Length=”标签中显示直线的长度(即两个端点之间的距离)。
请朋友们帮忙看一看,谢谢😭

public partial class Form1 : Form
{
    private Point startPoint;
    private Point endPoint;

    public Form1()
    {
        InitializeComponent();
    }

    private void Form1_MouseDown(object sender, MouseEventArgs e)
    {
        startPoint = new Point(e.X, e.Y);
    }

    private void Form1_MouseUp(object sender, MouseEventArgs e)
    {
        endPoint = new Point(e.X, e.Y);

        Graphics g = this.CreateGraphics();
        Pen pen = new Pen(Color.Black, 1);
        g.DrawLine(pen, startPoint, endPoint);

        double length = Math.Sqrt(Math.Pow(endPoint.X - startPoint.X, 2) + Math.Pow(endPoint.Y - startPoint.Y, 2));
        label1.Text = "Length=" + length.ToString("#0.00") + " pixels";
    }
}