0

我需要在我的打印文档上创建一个 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 的位置?

4

1 回答 1

1

尝试使用以下来源。

 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
于 2021-11-12T06:41:16.350 回答