你的问题需使用API函数来判别鼠标的坐标位置,当鼠标处于按钮位置时使 Option Explicit Private Type PointAPI X As Long Y As Long End Type Dim MousePos As PointAPI Private Declare Function GetCursorPos Lib "user32" (lpPoint As PointAPI) As Long Dim NewX As Long Dim NewY As LongPrivate Sub Command2_Click() Print "有没有办法去响应控件(commandbutton)事件?" End SubPrivate Sub Form_Load() Me.WindowState = 2 End SubPrivate Sub Timer1_Timer() GetCursorPos MousePos NewX = MousePos.X * Screen.TwipsPerPixelX NewY = MousePos.Y * Screen.TwipsPerPixelY - 300 Label1 = NewX Label2 = NewY If NewX >= Command2.Left And NewX <= Command2.Left + Command2.Width And NewY >= Command2.Top And NewY <= Command2.Height + Command2.Top Then Command2_Click Else Command2.Enabled = False Me.Cls End If End Sub
Option Explicit
Private Type PointAPI
X As Long
Y As Long
End Type
Dim MousePos As PointAPI
Private Declare Function GetCursorPos Lib "user32" (lpPoint As PointAPI) As Long
Dim NewX As Long
Dim NewY As LongPrivate Sub Command2_Click()
Print "有没有办法去响应控件(commandbutton)事件?"
End SubPrivate Sub Form_Load()
Me.WindowState = 2
End SubPrivate Sub Timer1_Timer()
GetCursorPos MousePos
NewX = MousePos.X * Screen.TwipsPerPixelX
NewY = MousePos.Y * Screen.TwipsPerPixelY - 300
Label1 = NewX
Label2 = NewY
If NewX >= Command2.Left And NewX <= Command2.Left + Command2.Width And NewY >= Command2.Top And NewY <= Command2.Height + Command2.Top Then
Command2_Click
Else
Command2.Enabled = False
Me.Cls
End If
End Sub