Option Explicit
Dim lin As Line
Private Sub cmdMouse_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim ctl As Control
Dim Ax As Single, Ay As Single, Bx As Single, By As Single
Dim r As Double, s As Double, d As Double
For Each ctl In Me.Controls
If ctl.ControlType = acLine Then
With ctl
If .LineSlant Then
Ax = .Left: Ay = .Top + .Height
Bx = .Left + .Width: By = .Top
Else
Ax = .Left: Ay = .Top
Bx = .Left + .Width: By = .Top + .Height
End If
End With
d = (Bx - Ax) ^ 2 + (By - Ay) ^ 2
r = ((X - Ax) * (Bx - Ax) + (Y - Ay) * (By - Ay)) / d
s = ((Ay - Y) * (Bx - Ax) - (Ax - X) * (By - Ay)) / d
d = Abs(s) * d ^ (1 / 2)
If d < 50 And 0 <= r And r <= 1 Then
Set lin = ctl
lin.BorderColor = vbRed
Exit For
End If
End If
Next ctl
End Sub
Private Sub cmdMouse_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Not lin Is Nothing Then
lin.BorderColor = vbBlack
Set lin = Nothing
End If
End Sub
|