Luca, here is an example of using the timer with image controls
1. In a new project and on a new form...
a. Add 1 image control. Name it imgRed. Add one of the red circle gifs to it
b. Add 1 image control. Name it imgYellow. Add one of the yellow circle gifs
c. Add 2 image controls: Name them Image1(0) and Image1(1)
d. Add a timer. Name is Timer1
2. Copy and paste this code to the form
Code:
Option Explicit
Private Declare Function GetCursorPos Lib "user32.dll" (ByRef lpPoint As POINTAPI) As Long
Private Declare Function ScreenToClient Lib "user32.dll" (ByVal hwnd As Long, ByRef lpPoint As POINTAPI) As Long
Private Type POINTAPI
x As Long
y As Long
End Type
Private Sub Form_Load()
Dim X As Long
imgRed.Visible = False
imgYellow.Visible = False
Timer1.Enabled = False
Timer1.Interval = 200
For X = Image1.LBound To Image1.UBound
Image1(X) = imgYellow
Next
End Sub
Private Sub Image1_MouseMove(Index As Integer, Button As Integer, Shift As Integer, x As Single, y As Single)
If Image1(Index).Tag = "" Then
If Timer1.Tag <> "" Then ' previous circle hasn't changed colors
Timer1.Enabled = False ' stop timer
Image1(Timer1.Tag).Tag = "" ' reset timer tag
Image1(Timer1.Tag) = imgYellow ' change circle
End If
Image1(Index) = imgRed ' change this circle
Image1(Index).Tag = "R" ' set tag as flag it is changed
Timer1.Tag = Index ' set timer tag to this circle index
Timer1.Enabled = True ' enable the timer
' show balloon tip
End If
End Sub
Private Sub Timer1_Timer()
Dim mousePT As POINTAPI, Index As Integer
GetCursorPos mousePT ' get mouse coords
ScreenToClient Me.hwnd, mousePT ' convert to form coords
mousePT.x = ScaleX(mousePT.x, vbPixels, Me.ScaleMode) ' convert to form scalemode
mousePT.y = ScaleY(mousePT.y, vbPixels, Me.ScaleMode)
Index = Val(Timer1.Tag) ' index of active circle
' see if in image coords
If mousePT.x < Image1(Index).Left Or mousePT.y < Image1(Index).Top Then
Timer1.Enabled = False
ElseIf mousePT.x > Image1(Index).Left + Image1(Index).Width Then
Timer1.Enabled = False
ElseIf mousePT.y > Image1(Index).Top + Image1(Index).Height Then
Timer1.Enabled = False
End If
If Timer1.Enabled = False Then ' outside of image
Timer1.Tag = "" ' reset flag
Image1(Index) = imgYellow ' change to yellow
Image1(Index).Tag = "" ' reset image tag
End If
End Sub
Now move your cursor over the circles.