1
votes

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 ?

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<Point> LinePoints = new List<Point>(); ? You probably will want to change to a List<List<Point>>, at least if your points are not all connected.. See here for an example - TaW
@TaW Thanks bro ^^ - Nemo

1 Answers

0
votes

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());
}