0

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

我在这里使用示例 Graphic - DrawLine - 画线并移动它

并在代码中稍作改动以绘制线条

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

但是当我移动它们时,我没有想要的东西......有什么帮助吗??

4

1 回答 1

1

您还没有写出您在应用程序中看到的效果,这会很有帮助。但是,查看您提供的代码似乎索引有问题。为了使用后续行,您应该使用 index 0和 index 1而不是02

试试这个代码:

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

于 2012-06-25T19:28:50.550 回答