在VB中怎么使鼠标放到按钮上使按钮变颜色

在VB中如何使鼠标放到按钮上使按钮变颜色
在VB中如何使鼠标放到按钮上使按钮变颜色

------解决方案--------------------
Option Explicit
'注意:COMMAND1的STYLE设置为1
Dim oldColor As Long

Private Sub Command1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Command1.BackColor = &HFF00FF
End Sub

Private Sub Form_Load()
oldColor = Me.BackColor
End Sub

Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Command1.BackColor = oldColor
End Sub

------解决方案--------------------
Option Explicit

'注意:COMMAND1的STYLE设置为1

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

Private Sub Command1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
With Command1
If (X < 0) Or (Y < 0) Or (X > .Width) Or (Y > .Height) Then
.BackColor = vbButtonFace
ReleaseCapture
Else
.BackColor = vbGreen
SetCapture .hwnd
End If
End With
End Sub