Option Explicit
Private Declare Function ReleaseCapture Lib "user32" () As Long
Private Declare Function SetCapture Lib "user32" (ByVal hwnd As Long) As Long
'先添加一个CommandButton控件..
'将Command1的Style设置为1
Private Sub Command1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If X > 0 And Y > 0 And X < Command1.Width And Y < Command1.Height Then
SetCapture Command1.hwnd
Command1.BackColor = vbRed
Command1.Font.Size = 20
Command1.Caption = "鼠标进入"
Else
Command1.BackColor = vbBlue
Command1.Font.Size = 16
Command1.Caption = "鼠标离开"
ReleaseCapture
End If
End Sub