il codice di MdE, può andar bene...
ma forse in questo modo hai più libertà di movimento per gestire ulteriori controlli, e poi, utilizzando come dicevo prima, la WindowFromPoint, puoi evitare di scrivere ogni volta le coordinate del controllo, anche in virtù del fatto che mi sembra di aver capito che potrebbero essere anche più di uno...
per provare il codice, metti sul form:
- 1 Timer
- 1 Pulsante con Style = Graphical
- 2 PictureBox
- 2 ImageBox con 2 immagini differenti
lascia tutti i nomi di default, e copia questo codice:
codice:
Private Declare Function GetCursorPos Lib "user32.dll" ( _
ByRef lpPoint As POINTAPI) As Long
Private Type POINTAPI
X As Long
Y As Long
End Type
Private Declare Function WindowFromPoint Lib "user32.dll" ( _
ByVal xPoint As Long, _
ByVal yPoint As Long) As Long
Dim ActControl As Object
Private Sub Command1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Set ActControl = Command1
Timer1.Enabled = True
End Sub
Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Set ActControl = Picture1
Timer1.Enabled = True
End Sub
Private Sub Picture2_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Set ActControl = Picture2
Timer1.Enabled = True
End Sub
Private Sub Timer1_Timer()
Dim pt As POINTAPI
If ActControl Is Nothing Then
Timer1.Enabled = False
Exit Sub
End If
On Error Resume Next
GetCursorPos pt
If WindowFromPoint(pt.X, pt.Y) = ActControl.hWnd Then
ActControl.Picture = Image1.Picture
Else
ActControl.Picture = Image2.Picture
Timer1.Enabled = False
Set ActControl = Nothing
End If
End Sub
Boolean