0

i want to draw a series of lines and move them but i want to connect the end point of line 1 to the start point of line 2 ... when i move line 1 or 2 ... the other line will affect by changing its point

i use the example here Graphic - DrawLine - draw line and move it

and change a little bit in code to make the draw lines

void LineMover_Paint(object sender, PaintEventArgs e)
{
    e.Graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High;
    e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;

    var pen = new Pen(Color.Black, 2);
    e.Graphics.DrawLine(pen, Lines[0].StartPoint, Lines[0].EndPoint);
    e.Graphics.DrawLine(pen, Lines[0].EndPoint, Lines[2].StartPoint);
    e.Graphics.DrawLine(pen, Lines[2].StartPoint, Lines[2].EndPoint);
}

but when i move them i do not have what i want ... any help ??

Community
  • 1
  • 1
user1477332
  • 325
  • 2
  • 4
  • 20

1 Answers1

1

You haven't written what is the effect you see in your application, which would be helpful. However, looking at the code you provided it seems that there is something wrong with the indices. In order to use subsequent lines, you should use index 0 and index 1 instead of 0 and 2.

Try this code:

void LineMover_Paint(object sender, PaintEventArgs e)
{
    e.Graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High;
    e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;



        var pen = new Pen(Color.Black, 2);
        e.Graphics.DrawLine(pen, Lines[0].StartPoint, Lines[0].EndPoint);
        e.Graphics.DrawLine(pen, Lines[0].EndPoint, Lines[1].StartPoint);
        e.Graphics.DrawLine(pen, Lines[1].StartPoint, Lines[1].EndPoint);

}

Let me know if it works for you. If not, please provide some more detailed information about it.

Another question is if you want to draw only two lines or more of them connected to its neighbours? For drawing more lines, you can consider using Graphics.DrawLines() method. It allows you to secify an array of points defining a set of connected lines. More information and a sample code can be found here: http://msdn.microsoft.com/en-us/library/7ewkcdb3.aspx.

Lukasz M
  • 5,635
  • 2
  • 22
  • 29