使用 e.graphics 创建 5 点星,但在 VB.NET 中将 x 和 y 起始位置设置为 110,110
Create 5 Point Star with e.graphics but set the x and y start position to 110,110 in VB.NET
我需要在我的打印文档上创建一个 15 点宽 x 15 点高的 5 点小星形,其中 x 起始位置为 110,y 起始位置为 110。
到目前为止我在网上找到的代码创建了一个星号,但是在左上角的 0,0 位置。
' Make the points for a star.
Dim pts(4) As Point
Dim cx As Integer = 15 \ 2
Dim cy As Integer = 15 \ 2
Dim theta As Double = -Math.PI / 2
Dim dtheta As Double = Math.PI * 0.8
For i As Integer = 0 To 4
pts(i).X = CInt(cx + cx * Math.Cos(theta))
pts(i).Y = CInt(cy + cy * Math.Sin(theta))
theta += dtheta
Next i
e.Graphics.FillPolygon(Brushes.Black, pts)
现在如何将星图移动到 x.110 y.110 位置?
尝试使用以下来源。
Private Sub DrawStar(ByVal prm_StartX As Integer, ByVal prm_StartY As Integer)
Try
Dim pts(4) As Point
Dim cx As Integer = prm_StartX
Dim cy As Integer = prm_StartY
Dim theta As Double = -Math.PI / 2
Dim dtheta As Double = Math.PI * 0.8
For i As Integer = 0 To 4
pts(i).X = CInt(cx + 7 * Math.Cos(theta))
pts(i).Y = CInt(cy + 7 * Math.Sin(theta))
theta += dtheta
Next i
Dim Pen As New Pen(Color.Red, 2)
' Draw
Dim formGraphics As System.Drawing.Graphics
formGraphics = Me.CreateGraphics()
formGraphics.DrawPolygon(Pen, pts)
Pen.Dispose()
formGraphics.Dispose()
Catch ex As Exception
End Try
End Sub
Private Sub Toy1Form_MouseClick(sender As Object, e As MouseEventArgs) Handles Me.MouseClick
DrawStar(e.X, e.Y)
End Sub
我需要在我的打印文档上创建一个 15 点宽 x 15 点高的 5 点小星形,其中 x 起始位置为 110,y 起始位置为 110。
到目前为止我在网上找到的代码创建了一个星号,但是在左上角的 0,0 位置。
' Make the points for a star.
Dim pts(4) As Point
Dim cx As Integer = 15 \ 2
Dim cy As Integer = 15 \ 2
Dim theta As Double = -Math.PI / 2
Dim dtheta As Double = Math.PI * 0.8
For i As Integer = 0 To 4
pts(i).X = CInt(cx + cx * Math.Cos(theta))
pts(i).Y = CInt(cy + cy * Math.Sin(theta))
theta += dtheta
Next i
e.Graphics.FillPolygon(Brushes.Black, pts)
现在如何将星图移动到 x.110 y.110 位置?
尝试使用以下来源。
Private Sub DrawStar(ByVal prm_StartX As Integer, ByVal prm_StartY As Integer)
Try
Dim pts(4) As Point
Dim cx As Integer = prm_StartX
Dim cy As Integer = prm_StartY
Dim theta As Double = -Math.PI / 2
Dim dtheta As Double = Math.PI * 0.8
For i As Integer = 0 To 4
pts(i).X = CInt(cx + 7 * Math.Cos(theta))
pts(i).Y = CInt(cy + 7 * Math.Sin(theta))
theta += dtheta
Next i
Dim Pen As New Pen(Color.Red, 2)
' Draw
Dim formGraphics As System.Drawing.Graphics
formGraphics = Me.CreateGraphics()
formGraphics.DrawPolygon(Pen, pts)
Pen.Dispose()
formGraphics.Dispose()
Catch ex As Exception
End Try
End Sub
Private Sub Toy1Form_MouseClick(sender As Object, e As MouseEventArgs) Handles Me.MouseClick
DrawStar(e.X, e.Y)
End Sub