• 主页
famoushzb 2004年12月21日
##### 请高手帮忙看一段code，十万火急！
Dim x1 As Single, y1 As Single
Dim x2 As Single, y2 As Single
Dim x3 As Single, y3 As Single
Dim x4 As Single, y4 As Single
Dim m1 As Single, n1 As Single
Dim m2 As Single, n2 As Single
Dim flag As Integer
Dim r As Long
Dim d As Long
Dim s As Integer

Private Sub Command1_Click()
End Sub

Private Sub Command2_Click()
Picture1.Cls
x1 = x2 = x3 = x4 = 0
y1 = y2 = y3 = y4 = 0
flag = r = d = s = 0
End Sub

Form4.Height = MDIForm1.ScaleHeight
Form4.Width = MDIForm1.ScaleWidth
Form4.Top = 0
Form4.Left = 0
End Sub

Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim k As Long
Dim a As Long
Dim b As Long
Dim c As Long
If s = 0 Then
If flag = 0 Then
Picture1.Cls
x1 = x2 = x3 = x4 = 0
y1 = y2 = y3 = y4 = 0
x1 = X
y1 = Y
flag = 1
Else
x2 = X
y2 = Y
r = Sqr(Abs(x1 - x2) ^ 2 + Abs(y1 - y2) ^ 2)
Picture1.Circle (x1, y1), r
flag = 0
s = 1
End If
Else
If flag = 0 Then
x3 = X
y3 = Y
flag = 1
Else
x4 = X
y4 = Y
Picture1.Line (x3, y3)-(x4, y4)
flag = 0
s = 0
End If
End If
If (x1 * y1 * x2 * y2 * x3 * y3 * x4 * y4) <> 0 Then
k = (y4 - y3) / (x4 - x3)
d = Abs(k * x1 - y1 + y3 - k * x3) / Sqr(k ^ 2 + 1)
a = k ^ 2 + 1
b = -2 * (x1 + k ^ 2 * x3 + k * y1 - k * y3)
c = x1 ^ 2 + k ^ 2 * x3 ^ 2 - 2 * k * y3 * x3 + y3 ^ 2 + 2 * k * y1 * x3 - 2 * y1 * y3 + y1 ^ 2 - r ^ 2
If (d = r) Then
m1 = Sqr(c)
n1 = k * (m1 - x3) + y3
End If
If (d < r) Then
m1 = (-b - Sqr(Abs(b ^ 2 - 4 * a * c))) / (2 * a)
n1 = k * (m1 - x3) + y3
m2 = (-b + Sqr(Abs(b ^ 2 - 4 * a * c))) / (2 * a)
n2 = k * (m2 - x3) + y3
End If
Else
a = b = c = d = k = m1 = m2 = n1 = n2 = 0
End If
End Sub

Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If m1 * n1 * m2 * n2 <> 0 Then
If (d = r) Then
Call catch(m1, n1, X, Y)
End If
If (d < r) Then
Call catch(m1, n1, X, Y)
Call catch(m2, n2, X, Y)
End If
End If
Call catch(x1, y1, X, Y)
Call catch(x3, y3, X, Y)
Call catch(x4, y4, X, Y)
Call catch((x3 + x4) / 2, (y3 + y4) / 2, X, Y)
End Sub
Private Sub catch(u As Single, v As Single, X As Single, Y As Single)
If ((u - X) * (u - X) + (v - Y) * (v - Y)) < 10000 Then
Picture1.Circle (u, v), 50, RGB(255, 0, 0)
Else
Picture1.Circle (u, v), 50, Picture1.BackColor
End If
End Sub

...全文
40 点赞 收藏 1

1 条回复

VB基础类

2738

19.7w+

VB 基础类