Guan

Guan

  • NA
  • 10
  • 13.2k

Drawing a line between two points with Mouseclick

Aug 30 2010 4:19 PM
Hello everyone

I'm trying to make a very basic dwawing application where you can draw (eg. a line) on a panel. 
The very basic code to draw a line on the panel by code is this:

       private void panel1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
        {
            Pen blackPen = new Pen(Color.Black, 4);
            int X1 = 0, Y1 = 0, X2 = 250, Y2 = 100;
            Graphics graphics = panel1.CreateGraphics();
            e.Graphics.DrawLine(blackPen, X1, Y1, X2, Y2);
            blackPen.Dispose();
        }


Now is my question: how do i have to write the code so i can draw a line with 2 mouseclicks? 
I think we could use point structures ? But how do i have to write everything ?

Answers (4)