绘制一系列线并移动它们

时间:2012-06-25 15:58:16

标签: c# .net graphics drawing

我想绘制一系列线并移动它们但我想将第1行的终点连接到第2行的起点...当我移动第1行或第2行时...另一行会影响通过改变它的观点

我在这里使用这个例子 Graphic - DrawLine - draw line and move it

并在代码中稍微改变一下以制作绘制线

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

但是当我移动它们时,我没有我想要的......任何帮助?

1 个答案:

答案 0 :(得分:1)

您还没有写下您在应用程序中看到的效果,这会有所帮助。但是,查看您提供的代码似乎表明索引存在问题。要使用后续行,您应该使用索引 0 和索引 1 而不是 0 2 。< / p>

试试这段代码:

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

}

让我知道它是否适合您。如果没有,请提供一些更详细的信息。

另一个问题是,如果您只想绘制两条或更多条连接到其邻居的线路?要绘制更多行,可以考虑使用Graphics.DrawLines()方法。它允许您隐藏定义一组连接线的点阵列。可以在此处找到更多信息和示例代码:http://msdn.microsoft.com/en-us/library/7ewkcdb3.aspx

相关问题