C# 保存绘制的椭圆在List<Point>中的位置?

C# Save location of drawn Ellipse in List<Point>?

这里有一个小问题,我没有找到合适的答案。 我想保存椭圆的绘制位置,以便稍后在 2 个椭圆之间画一条线,所以如果可能的话,我想将其保存为一个点。

 protected override void OnPaint(PaintEventArgs e)
    {
        base.OnPaint(e);
        screen.Clear(Color.Black);

        using (var p = new Pen(Color.White, 2))
        {
            for (int x = 0; x < p1List.Count; x++)
            {
                screen.DrawLine(p, p1List[x], p2List[x]);
            }
        }

        List<Point> punten = new List<Point>();


        foreach (var pair in this.droppedShapes)
        {
            var shapeType = pair.Item2; // Reveal your own shape object here
            var location = pair.Item1;


            switch (shapeType) // Reveal your own shape object here
            {
                case 0:
                    screen.DrawRectangle(whitePen, location.X - 10, location.Y - 10, 40, 40);
                    screen.DrawString("&", new Font(FontFamily.GenericMonospace, (float)28), whiteBrush, location.X - 11, location.Y - 13);
                    //input       
                    screen.DrawLine(whitePen, location.X - 25, location.Y, location.X - 10, location.Y );
                    screen.FillEllipse(greenBrush, location.X - 30, location.Y - 5, 10, 10);
                    punten.Add(); //add the location of the "ellipse"
                    //input       
                    screen.DrawLine(whitePen, location.X - 25, location.Y + 20, location.X - 10, location.Y + 20);
                    screen.FillEllipse(greenBrush, location.X - 30, location.Y + 15, 10, 10);

                    //output      
                    screen.DrawLine(whitePen, location.X + 30, location.Y + 10, location.X + 45, location.Y + 10);
                    screen.FillEllipse(greenBrush, location.X + 40, location.Y + 5, 10, 10);

我已经添加了行 "punten.Add()" 因为这是我要保存位置的行。 如果有更好的方法,请打我!

我觉得没问题,只需更换你的

punten.Add();

punten.Add(new Point(location.X, location.Y));

或类似的东西,用于在位置之间绘制线条。 请注意,如果命中 switch 语句中的 case 0,这只会将 Points 添加到您的列表中,否则您的 List 可能不包含任何 Points(或者您将 Points 添加到其他 case 部分的列表中)。