旋转使用GraphicsPath绘制的多边形

时间:2015-08-28 13:02:42

标签: vb.net graphics polygon rotatetransform

我想在右上角旋转多边形-90度。

这是我绘制多边形的代码:

Private Sub Form1_Click(sender As Object, e As EventArgs) Handles MyBase.Click
    Dim g As Graphics = Me.CreateGraphics()
    Dim p As New Drawing2D.GraphicsPath()

    Dim startPoint As Point = PointToClient(Cursor.Position)

    Dim littleAngle As Integer = 4
    Dim anglesDifference As Integer = 2
    Dim bigAngle As Integer = littleAngle + anglesDifference
    Dim bigSegment As Integer = 50

    Dim p1, p2, p3, p4, p5 As Point

    p1 = New Point(startPoint.X + littleAngle, startPoint.Y - littleAngle)
    p2 = New Point(startPoint.X + littleAngle + bigSegment, startPoint.Y - littleAngle)
    p3 = New Point(startPoint.X + littleAngle + bigSegment + littleAngle, startPoint.Y)
    p4 = New Point(startPoint.X + littleAngle - anglesDifference + bigSegment, startPoint.Y + bigAngle)
    p5 = New Point(startPoint.X + bigAngle, startPoint.Y + bigAngle)

    p.AddLines({startPoint, p1, p2, p3, p4, p5})

    Dim pen As New Pen(Color.Red, 1)
    g.FillPath(New SolidBrush(Color.Red), p)
    g.DrawPath(pen, p)

    Dim translateMatrix As New Matrix
    translateMatrix.RotateAt(-90, New PointF(p.GetBounds.Width, 0))
    p.Transform(translateMatrix)

    g.FillPath(New SolidBrush(Color.Red), p)
    g.DrawPath(pen, p)
End Sub

以下是使用上述代码绘制的内容:

the result I've

以下是我想要的例子:

enter image description here

1 个答案:

答案 0 :(得分:1)

要获得所需内容,只需将translateMatrix.RotateAt(-90, New PointF(p.GetBounds.Width, 0))替换为:

即可
translateMatrix.RotateAt(-90, p3)