speed issue with mouse location

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
End If
Next i
End If
end sub

08-19-2006, 03:35 PM
Hi, I would try to extend the logic to check if you are in the same rectangle as you were in the last mouse event, if this is the case then you do not need to refresh. This should filter out many refreshes. I would also use Me.Invalidate as opposed to Me.Refresh

Good luck


EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum