0

I need to create a small 5 point star that is 15 points wide by 15 points high, where the x starting position is 110 and the y starting position is 110 on my print document.

the code I found online so far creates a star, but in the top left corner at 0,0 position.

         ' 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)

how do i now move the star graphic to position x.110 y.110?

1 Answers1

1

Try using the sources below.

 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
Think2826
  • 201
  • 1
  • 7
  • Thank you, your answer actually draws it on my user form and not my printdocument but i managed to see where you made the change to get the position to where i needed it to draw it for my print document. – Andy Andromeda Nov 12 '21 at 10:01