rpetersen
08-18-2006, 02:41 PM
I am using VB.net 2005.
I have defined arrays of rectangles (the most being 18) that I am using to highlight features in a bitmap. When the mouse moves, I search through the array in the mousemove event and then paint the rectangle that contains the location of the mouse pointer in the paint event. It runs fine on my pentium 4, but there is a slight lag on the older computers in the plant. The algorithm is inefficient, but I am not sure of any other way.
There has to be a better algorithm, or a different way to accomplish this task that will run faster. Can anybody help?
In the example below I have an array of only 5 rectangles that I search through, but even this bit is slow on older hardware.
Private Sub Form1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseMove
Dim i As Integer
loc = e.Location
For i = 1 To 5
If rect(i).Contains(loc) Then
box = i
Me.Refresh()
End If
Next i
End If
end sub
I have defined arrays of rectangles (the most being 18) that I am using to highlight features in a bitmap. When the mouse moves, I search through the array in the mousemove event and then paint the rectangle that contains the location of the mouse pointer in the paint event. It runs fine on my pentium 4, but there is a slight lag on the older computers in the plant. The algorithm is inefficient, but I am not sure of any other way.
There has to be a better algorithm, or a different way to accomplish this task that will run faster. Can anybody help?
In the example below I have an array of only 5 rectangles that I search through, but even this bit is slow on older hardware.
Private Sub Form1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseMove
Dim i As Integer
loc = e.Location
For i = 1 To 5
If rect(i).Contains(loc) Then
box = i
Me.Refresh()
End If
Next i
End If
end sub