C# 画一系列的线并移动它们

C# 画一系列的线并移动它们,c#,.net,graphics,drawing,C#,.net,Graphics,Drawing,我想画一系列的线并移动它们,但我想连接线1的端点到线2的起点。。。当我移动第1行或第2行时。。。另一条线将通过更改其点来影响 我在这里使用这个例子 并在代码中稍加修改以绘制线条 void LineMover_Paint(object sender, PaintEventArgs e) { e.Graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High; e.Graphics.Smoot

我想画一系列的线并移动它们,但我想连接线1的端点到线2的起点。。。当我移动第1行或第2行时。。。另一条线将通过更改其点来影响

我在这里使用这个例子

并在代码中稍加修改以绘制线条

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

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

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

请尝试以下代码:

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

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


另一个问题是,如果你只想画两条或更多的线与它的邻居相连?为了绘制更多的线条,可以考虑使用<代码>图形.DraveStudio()< <代码>方法。它允许您加密定义一组连接线的点阵列。更多信息和示例代码可在此处找到:。

嗯。。。发生了什么你不想发生的事?很难理解。考虑使用Studio.TrimeTeaTror(),这样整个绘图就被抵消了,你不必再修改各个点。谢谢各位…没有问题。我很高兴帮助你:)。