这个是近似画法 我数学学的不好,有错误的地方希望大家指正 把一下代码粘贴到Form1上,设置Form1.Autoredraw=true scalemode=3 (象素) Option Explicit Private Type POINTAPI x As Long y As Long d As Single End Type Sub DrawShape(Optional Lines As Long, Optional r As Long, Optional x As Single, Optional y As Single) If Lines < 3 Then Exit Sub If r < 10 Then r = 10 If x < 10 Then x = 20 If y < 10 Then y = 20Dim i As Long Dim dr As Single Dim Points() As POINTAPIdr = 360 / Lines ReDim Points(Lines) As POINTAPI Points(0).x = x Points(0).y = y
For i = 1 To Lines With Points(i) .d = dr * i / 57 .x = Cos(.d) * r + Points(i - 1).x .y = Sin(.d) / 1 * r + Points(i - 1).y End With Next For i = 1 To Lines - 1 Me.Line (Points(i - 1).x, Points(i - 1).y)-(Points(i).x, Points(i).y), vbBlack Next Me.Line (Points(0).x, Points(0).y)-(Points(Lines - 1).x, Points(Lines - 1).y), vbBlack End SubPrivate Sub Form_Load() Me.ClsDrawShape 5, 60, 200, 100End Sub
把一下代码粘贴到Form1上,设置Form1.Autoredraw=true scalemode=3 (象素)
Option Explicit
Private Type POINTAPI
x As Long
y As Long
d As Single
End Type
Sub DrawShape(Optional Lines As Long, Optional r As Long, Optional x As Single, Optional y As Single)
If Lines < 3 Then Exit Sub
If r < 10 Then r = 10
If x < 10 Then x = 20
If y < 10 Then y = 20Dim i As Long
Dim dr As Single
Dim Points() As POINTAPIdr = 360 / Lines ReDim Points(Lines) As POINTAPI
Points(0).x = x
Points(0).y = y
For i = 1 To Lines
With Points(i)
.d = dr * i / 57
.x = Cos(.d) * r + Points(i - 1).x
.y = Sin(.d) / 1 * r + Points(i - 1).y
End With Next
For i = 1 To Lines - 1
Me.Line (Points(i - 1).x, Points(i - 1).y)-(Points(i).x, Points(i).y), vbBlack
Next
Me.Line (Points(0).x, Points(0).y)-(Points(Lines - 1).x, Points(Lines - 1).y), vbBlack
End SubPrivate Sub Form_Load()
Me.ClsDrawShape 5, 60, 200, 100End Sub