0

Hi i would like to know how can i get points from the second line i draw. Here is my code, for now i can draw lines with mouse event and draw lines with a button where i write the coordinates of the points. public partial class Form1 : Form { Graphics drawArea; private Point p1, p2; List p1List = new List(); List p2List = new List();

    public Form1()
    {
        InitializeComponent();
        drawArea = panel1.CreateGraphics();
    }

    private void panel1_Paint(object sender, PaintEventArgs e)
    {
        System.Drawing.Graphics graphicsObj;

        graphicsObj = CreateGraphics();

        Pen p = new Pen(System.Drawing.Color.Black, 1);

        for (int x = 0; x < p1List.Count; x++)
        {
            drawArea.DrawLine(p, p1List[x], p2List[x]);
        }
    }

    private void button1_Click(object sender, EventArgs e)
    {      
        p1.X = Convert.ToInt32(textBox1.Text);
        p1.Y = Convert.ToInt32(textBox3.Text);
        p2.X = Convert.ToInt32(textBox2.Text);
        p2.Y = Convert.ToInt32(textBox4.Text);

        Pen p = new Pen(System.Drawing.Color.Black, 2);
        drawArea.DrawLine(p, p1.X, p1.Y, p2.X, p2.Y);
    }

    void panel1_MouseDown(object sender, MouseEventArgs e)
    {
        if (p1.X == 0)
        {
            p1.X = e.X;
            p1.Y = e.Y;
        }
        else
        {
            p2.X = e.X;
            p2.Y = e.Y;

            p1List.Add(p1);
            p2List.Add(p2);

            panel1.Invalidate();
            p1.X = 0;
        }
    }
}

}

vidooo
  • 135
  • 1
  • 1
  • 9
  • Can you further explain what you mean by "Get points from the second line I draw" ? I understand what your code does, but not your question. – Wassim H Mar 08 '16 at 19:22
  • when i draw first line i get my points p1.x and p1.y + p2.x and p2.Y i want to know how can i get points from the second line i draw for example i would like to get p3.x and p3.y + p4.x and p4.y so i can calculate the intersection between them. – vidooo Mar 08 '16 at 19:25
  • How is the second line being drawn ? You mention two methods : By entering the coordinates, or by mouse events. Both methods should give you the coordinates (either through the textbox coordinates or the MouseEventArgs). Am I understanding this wrong ? – Wassim H Mar 08 '16 at 19:30
  • You are understanding it correct, i just want to know what is the way to store the coordiantes from points of both lines and then call the coordinates from both lines in other function. – vidooo Mar 08 '16 at 19:34
  • Oh, there are many ways of doing it. Create a "Line" struct that holds two tuples for every coordinate of both points. Or create a List> that contains all tuples that correspond to a single line each (defined by all four points). – Wassim H Mar 08 '16 at 19:46
  • Thanks for the reply i will give it a shot :) – vidooo Mar 08 '16 at 20:15

0 Answers0