Is it possible to check if a certain line was clicked, like a function like.
. I need it to work with a array of lines.Code:Line1_Click(index as integer)
Printable View
Is it possible to check if a certain line was clicked, like a function like.
. I need it to work with a array of lines.Code:Line1_Click(index as integer)
since line doesnt have any events. Label can be used with '_______'(group of under score '_' character ) and then you can use the Label's click event to increment a static variable
hope i understood your requirement clearly if not please explain it in detail
his lines are at an angle, and he has other code relating to lines, so label replacements are not only impractical, but would also make his code not work.
Since you know where the lines start and end you can determine if the mouse is over one or not by doing the maths...
It might be not quite be what you were hoping for but it works.Code:Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim sX As Long, eX As Long, sY As Long, eY As Long
Dim Ln As Line, Over As Boolean, Grad As Single
For Each Ln In Line1
Over = False
With Ln
'first check if the mouse is in the bounds of the lines rectangle
If .X1 < .X2 Then sX = .X1: eX = .X2 Else sX = .X2: eX = .X1
If X >= sX Then
If X <= eX Then
If .Y1 < .Y2 Then sY = .Y1: eY = .Y2 Else sY = .Y2: eY = .Y1
If Y >= sY Then
If Y <= eY Then
'if so check if the mouse is near the line
If eX <> sX Then 'to avoid div 0
Grad = (eY - sY) / (eX - sX)
If Abs((X - sX) * Grad - (Y - sY)) <= 45 Then Over = True
'<= 45 assumes a scalemode of twips at 15/pixel
Else
Over = True
End If
End If
End If
End If
End If
End With
If Over = True Then
If Ln.BorderWidth <> 3 Then Ln.BorderWidth = 3
Else
If Ln.BorderWidth <> 1 Then Ln.BorderWidth = 1
End If
Next Ln
End Sub