需要在线条中创建圆角?

时间:2011-09-08 05:59:10

标签: c#

我正在尝试创建visio中的连接符号。我使用Graphics.Drawline方法创建了这些连接器。但是我不知道如何在像Microsoft Visio中那样弯曲曲线。

代码:

protected override void Render(Graphics gfx)
{
    PointF[] pts = GetPathPoints();
    gfx.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
    float x = (float)((pts[0].X + pts[1].X) / 2 - 5);
    float y = 0F;

    PointF start = new PointF((float)(pts[0].X), (float)(pts[0].Y));
    PointF end = new PointF((float)(pts[1].X), (float)(pts[1].Y));

    PointF pt1 = new PointF((float)(start.X), (float)(start.Y-50));
    PointF pt2 = new PointF((float)(end.X), (float)(end.Y - 50));

    using (Pen pen = this.LineStyle.CreatePen())
    {
        gfx.DrawLine(pen, start, pt1);
        gfx.DrawLine(pen, pt1, pt2);
        gfx.DrawLine(pen, pt2, end);
    }
}

请在下面的链接中查看具有平滑弯曲的连接器: http://en.wikipedia.org/wiki/File:BPMN-CollectVotes.jpg

如何在visio中绘制带圆角线的线条?

2 个答案:

答案 0 :(得分:1)

您需要使用GraphicsPath对象。也准备失去一些头发:))

查看PaintLineHighlight方法@ http://xacc.svn.sourceforge.net/viewvc/xacc/xacc/Drawing/Utils.cs?revision=90&view=markup

答案 1 :(得分:0)

使用直线上限。

pen.StartCap = System.Drawing.Drawing2D.LineCap.Round;
pen.EndCap = System.Drawing.Drawing2D.LineCap.Round;

https://docs.microsoft.com/en-us/dotnet/framework/winforms/advanced/how-to-draw-a-line-with-line-caps