急需用vb画多角形源代码,在线等待!给100分!!

zichuan1979 2003-12-13 08:59:05
用vb实现.输入角数.立刻在窗体中画出角数所对应的多角形
例如: 输入5.当鼠标点击窗体时.即可画出五角星!! 再线等待!!!!!!
...全文
9 点赞 收藏 3
写回复
3 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
a11s 2003-12-13
这个是近似画法 我数学学的不好,有错误的地方希望大家指正
把一下代码粘贴到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 = 20

Dim i As Long
Dim dr As Single
Dim Points() As POINTAPI

dr = 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 Sub

Private Sub Form_Load()
Me.Cls

DrawShape 5, 60, 200, 100

End Sub
回复
zichuan1979 2003-12-13
不需要考虑半径
回复
a11s 2003-12-13
不考虑半径么?
回复
发动态
发帖子
VB基础类
创建于2007-09-28

7453

社区成员

VB 基础类
申请成为版主
社区公告
暂无公告