vb Code:
Option Explicit
Private Declare Function SetCapture Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function ReleaseCapture Lib "user32" () As Long
Private Declare Function GetCapture Lib "user32" () As Long
Private Const vbGray = &H8000000F
Private Sub Command1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
'the button style must be set to graphical for this to work
If (X < 0) Or (Y < 0) Or (X > Command1.Width) Or (Y > Command1.Height) Then
ReleaseCapture ' the mouse is no longer over the button, change backcolor to gray
Command1.BackColor = vbGray
ElseIf GetCapture() <> Command1.hwnd Then
SetCapture Command1.hwnd ' the mouse is over the button, change backcolor to cyan
Command1.BackColor = vbCyan
End If
End Sub