请教关于vb中画拖动五角星的问题(有原代码,只需进行修改)在线等候,马上给分,可能有一点难,请各位大虾帮忙
我有一个画好的五角星的程序,以画好,且可拖动,但拖动后就变的不规范了,可以粘下来运行看看就知道效果了,请教各位帮忙解决,代码如下:
Option Explicit
Private Type USERPOINT
X As Long
Y As Long
Alpha As Double
End Type
Dim ox As Long, oy As Long, w As Long
Const PI = 3.14159265
Private Function FSin(ByVal X As Double) As Double
FSin = Sin(X * PI / 180)
Debug.Print FSin
End Function
Private Function FCos(ByVal X As Double) As Double
FCos = Cos(X * PI / 180)
Debug.Print FCos
End Function
Private Function TurnPoint(pt As USERPOINT, ByVal n As Double) As USERPOINT
Dim r As Double, p As USERPOINT
r = Sqr(pt.X * pt.X + pt.Y * pt.Y) + w
p.X = r * FCos(pt.Alpha + n)
p.Y = r * FSin(pt.Alpha + n)
p.Alpha = pt.Alpha + n
TurnPoint = p
End Function
Private Sub Form_Load()
Me.AutoRedraw = True
Me.ScaleMode = 3
Me.DrawWidth = 1
End Sub
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
ox = X
oy = Y
End Sub
Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
w = Sqr((X - ox) * (X - ox) + (oy - Y) * (oy - Y))
Dim pts(0 To 4) As USERPOINT
Dim pst(0 To 4) As USERPOINT
Dim i, j As Long
Me.AutoRedraw = True
Me.ScaleMode = 3
Me.DrawWidth = 1
pts(0).X = 0
pts(0).Y = 30
pts(0).Alpha = 90
pst(0).X = 0
pst(0).Y = -60
pst(0).Alpha = -90
For i = 0 To 4
pts(i) = TurnPoint(pts(0), 72 * i)
Next
For j = 0 To 4
pst(j) = TurnPoint(pst(0), 72 * j)
Next
Line (ox + pts(0).X, oy + pts(0).Y)-(ox + pst(3).X, oy + pst(3).Y), QBColor(2)
Line (ox + pst(3).X, oy + pst(3).Y)-(ox + pts(1).X, oy + pts(1).Y), QBColor(6)
Line (ox + pts(1).X, oy + pts(1).Y)-(ox + pst(4).X, oy + pst(4).Y), vbRed
Line (ox + pst(4).X, oy + pst(4).Y)-(ox + pts(2).X, oy + pts(2).Y), QBColor(5)
Line (ox + pts(2).X, oy + pts(2).Y)-(ox + pst(0).X, oy + pst(0).Y), QBColor(9)
Line (ox + pst(0).X, oy + pst(0).Y)-(ox + pts(3).X, oy + pts(3).Y), QBColor(5)
Line (ox + pts(3).X, oy + pts(3).Y)-(ox + pst(1).X, oy + pst(1).Y), QBColor(4)
Line (ox + pst(1).X, oy + pst(1).Y)-(ox + pts(4).X, oy + pts(4).Y), QBColor(3)
Line (ox + pts(4).X, oy + pts(4).Y)-(ox + pst(2).X, oy + pst(2).Y), QBColor(0)
Line (ox + pst(2).X, oy + pst(2).Y)-(ox + pts(0).X, oy + pts(0).Y), QBColor(1)
End Sub