Make your own free website on
Make An Hover Button

This Button will change his color when the mouse pointer is on it


Add 1 Command Button (named Command1)
Set the Command Button Style property to 1 - Graphical.

Module Code

Public Declare Function SetCapture Lib "user32" (ByVal hwnd As Long) As Long
Public Declare Function ReleaseCapture Lib "user32" () As Long

Form Code

Public Sub sysControlHighLight(ctl As Control, X As Single, _
Y As Single, OriginalBackColor As Long, NewBackColor As Long)
Dim HitTest As Long
    On Error Resume Next
    'test for control hwnd, if error simply exit
    HitTest = ctl.hwnd
    If Err.Number <> 0 Then Exit Sub
    With ctl
         If (X < 0) Or (Y < 0) Or (X > .Width) Or (Y > .Height) Then
            .BackColor = OriginalBackColor
                SetCapture .hwnd
                .BackColor = NewBackColor
        End If
   End With
    On Error GoTo 0
End Sub

Private Sub Command1_MouseMove(Button As Integer, _
Shift As Integer, X As Single, Y As Single)
'replace the 'Command1' below and above with your Command Button name
'replace the 'vbBlue' below with the initial button's color
'replace the 'vbRed' below with the color of the button when the mouse is on it.
sysControlHighLight Command1, X, Y, vbBlue, vbRed
End Sub

Private Sub Form_Load()
'replace the 'vbBlue' below with your preferred button's color
Command1.BackColor = vbBlue
End Sub

Go Back