|
-
Aug 3rd, 2007, 12:20 AM
#1
Thread Starter
Addicted Member
Line1_Click(index as integer)
Is it possible to check if a certain line was clicked, like a function like.
Code:
Line1_Click(index as integer)
. I need it to work with a array of lines.
-
Aug 3rd, 2007, 12:36 AM
#2
Member
Re: 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
-
Aug 3rd, 2007, 12:50 AM
#3
Addicted Member
Re: Line1_Click(index as integer)
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.
-
Aug 3rd, 2007, 04:46 AM
#4
Re: Line1_Click(index as integer)
Since you know where the lines start and end you can determine if the mouse is over one or not by doing the maths...
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
It might be not quite be what you were hoping for but it works.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|