.NET GDI+: Drawing lines with rounded corners

后端 未结 3 987
名媛妹妹
名媛妹妹 2021-01-21 09:52

Given an array of points, it is easy to draw a line based on these, e.g. using the GraphicsPath class.

For instance, the following array of points...

[0]         


        
3条回答
  •  难免孤独
    2021-01-21 10:11

    This is the function I use to draw a rectangle with rounded corners... from this you may calculate the angle of each line.

    Public Sub DrawRoundRect(ByVal g As Graphics, ByVal p As Pen, ByVal x As Single, ByVal y As Single, ByVal width As Single, ByVal height As Single, ByVal radius As Single)
        Dim gp As GraphicsPath = New GraphicsPath
        gp.AddLine(x + radius, y, x + width - (radius * 2), y)
        gp.AddArc(x + width - (radius * 2), y, radius * 2, radius * 2, 270, 90)
        gp.AddLine(x + width, y + radius, x + width, y + height - (radius * 2))
        gp.AddArc(x + width - (radius * 2), y + height - (radius * 2), radius * 2, radius * 2, 0, 90)
        gp.AddLine(x + width - (radius * 2), y + height, x + radius, y + height)
        gp.AddArc(x, y + height - (radius * 2), radius * 2, radius * 2, 90, 90)
        gp.AddLine(x, y + height - (radius * 2), x, y + radius)
        gp.AddArc(x, y, radius * 2, radius * 2, 180, 90)
        gp.CloseFigure()
        g.DrawPath(p, gp)
        gp.Dispose()
    End Sub
    

    Hope this help you in the harder part of trigonometry ;)

提交回复
热议问题