我需要創建一個 5 磅的小星星,寬 15 磅,高 15 磅,在我的列印檔案上,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 的位置?
uj5u.com熱心網友回復:
嘗試使用以下來源。
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
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/362713.html
上一篇:使用引數字串制作文本框的功能
