簡體   English   中英

在繪制的點之間畫一條線

[英]Drawing a line between the drawn points

我基於某些功能在圖像上繪制了一些點,然后我想用一條線將這些點連接在一起

        List<Point> LinePoints = new List<Point>();
        LinePoints.Add(p1);
        LinePoints.Add(p2);
        LinePoints.Add(p3);

在繪畫事件中:

            Pen p = new Pen(Color.Blue);
            if (LinePoints.Count > 1)
            {
                e.Graphics.DrawLines(p, LinePoints.ToArray());
            }

在第一個時間點之間繪制線,但在下一個迭代中
我將其他一些點添加到LinePoints列表中。
在這種情況下,將刪除舊的繪制線,並繪制下一條
但我不想刪除舊行。

如何在不刪除舊線的情況下在添加到列表LinePoints所有新點之間繪制線?

創建這樣的點列表:

List<Point> LinePoints = new List<Point>();
List<List<Point>> LinePointsSet = new List<List<Point>>();

然后添加點集:

LinePoints.Clear();
LinePoints.Add(p1);
LinePoints.Add(p2);
LinePoints.Add(p3);
LinePointsSet.Add(LinePoints.ToList());

並在Paint事件循環中遍歷所有列表:

foreach (var points in LinePointsSet)
{
    if (points.Count > 1) e.Graphics.DrawLines(Pens.Blue, points.ToArray());
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM