1

I draw some points over image based on some features, then i want to connect these points together with a line

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

and in the paint event:

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

In the first time line is drawn between points , but in the next iteration
i will add some other points to the list LinePoints.
In this case the old drawn line is removed and the next one is drawn
but i don not want to remove the old lines.

How to draw line between all new points which are added to the list LinePoints without remove the old lines ?

Nemo
  • 203
  • 3
  • 12
  • 1
    What are you targetting: Winforms, WPF, ASP..? YOU should __always__ TAG your questions correctly so one can see it on the questions page! - _t in the next iteration i will add some other points to the list _ Show that code! Does it also include `List LinePoints = new List();` ? You probably will want to change to a List>, at least if your points are not __all__ connected.. See [here for an example](https://stackoverflow.com/questions/26936109/how-do-i-save-a-winforms-panels-drawing-content-to-a-file/26938635#26938635) – TaW Jul 11 '18 at 16:17
  • @TaW Thanks bro ^^ – Nemo Jul 11 '18 at 17:28

1 Answers1

0

Create point lists like this:

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

Thn add sets of points:

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

And in the Paint event loop over all lists:

foreach (var points in LinePointsSet)
{
    if (points.Count > 1) e.Graphics.DrawLines(Pens.Blue, points.ToArray());
}
TaW
  • 53,122
  • 8
  • 69
  • 111
  • Thanks i just create a new list every time LinePoints=new List();then add it to the list> Thanks bro – Nemo Jul 11 '18 at 17:27