Search code examples
c#listgdi

how can I add Line coordinates in a list and then use them to draw lines again?


This is what I am trying:

private List liLines = new List<int>;
CDrawer can = new CDrawer(800, 800);
public void Form1_Load(object sender, EventArgs e)
{
    can.MouseLeftClick += new GDIDrawerMouseEvent(Can_MouseLeft);
    can.MouseRightClick += new GDIDrawerMouseEvent(Can_MouseRight);
    System.Threading.Thread.Sleep(50);            
}

void DrawLineItem()
{           
    can.AddLine(X1, Y1, X2, Y2, Color.White, 5);
    liLines.Add(new DrawLineItem(X1, Y1, X2, Y2));
}

Please help.Thank you.


Solution

  • Shooting from the hip (basics only): Define

    • class Coord { public double X; public double Y; Coord(double x, double y) { X = x; Y = y; } }
    • class Line { public Coord P1; public Coord P2; Line(Coord p1, Coord p2) { P1 = p1; P2 = p2; } }

    Then you can use var lines = new List<Line>()
    and do lines.Add(new Line(new Coordinate(1,2), new Coordinate(3,4));.