我想画一系列的线并移动它们,但是我想把线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);
}但是当我移动它们的时候我没有得到我想要的.有什么帮助吗??
发布于 2012-06-26 03:28:51
您还没有编写您在应用程序中看到的效果,这将是有帮助的。但是,查看您提供的代码,索引似乎有问题。为了使用后续行,您应该使用index和index 1而不是and 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);
}如果对你有效,请让我知道。如果没有,请提供更详细的信息。
另一个问题是,如果你只想画两条或更多的线连接到它的邻居?要绘制更多的线条,可以考虑使用Graphics.DrawLines()方法。它允许您指定定义一组连接直线的点数组。更多信息和示例代码可以在这里找到:http://msdn.microsoft.com/en-us/library/7ewkcdb3.aspx。
https://stackoverflow.com/questions/11192855
复制相似问题