如何通过标签模仿旋钮?

我在表单上有两个标签

lab01_Click: lab02.Caption = lab02.Caption + 1 

有没有办法使用lab01作为旋钮?
如果我一直按它 – 然后lab02.Caption应该不断变化?

您也可以将数据存储在Tag属性中

例如

 Private Sub Label1_Click() If Label1.Tag = "" Then Label1.Tag = 0 Label1.Tag = CLng(Label1.Tag) + 1 Label1.Caption = "Increment: " & Label1.Tag End Sub Private Sub Label2_Click() If Label1.Tag = "" Then Label1.Tag = 0 Label1.Tag = CLng(Label1.Tag) - 1 Label1.Caption = "Increment: " & Label1.Tag End Sub 

更新:好吧,我看到你想保持它递增,如果点击被压低。 我能想到的唯一方法是重新触发定时器事件的讨厌的“黑客”。 您将需要更新对象名称Userform1Label1Label2并可能需要将Private Declare Function调整为64位Private Declare PtrSafe Function

尝试在MODULE

 Option Explicit Private Declare Function SetTimer Lib "user32" _ (ByVal hWnd As Long, _ ByVal nIDEvent As Long, _ ByVal uElapse As Long, _ ByVal lpTimerFunc As Long) As Long Private Declare Function KillTimer Lib "user32" _ (ByVal hWnd As Long, _ ByVal nIDEvent As Long) As Long Private m_TimerID As Long 'Note: The duration is measured in milliseconds. ' 1,000 milliseconds = 1 second Public Sub StartTimer(ByVal Duration As Long) 'If the timer isn't already running, start it. If m_TimerID = 0 Then If Duration > 0 Then m_TimerID = SetTimer(0, 0, Duration, AddressOf TimerEvent) If m_TimerID = 0 Then MsgBox "Timer initialization failed!" End If Else MsgBox "The duration must be greater than zero." End If Else MsgBox "Timer already started." End If End Sub Public Sub StopTimer() 'If the timer is already running, shut it off. If m_TimerID <> 0 Then KillTimer 0, m_TimerID m_TimerID = 0 Else MsgBox "Timer is not active." End If End Sub Public Property Get TimerIsActive() As Boolean 'A non-zero timer ID indicates that it's turned on. TimerIsActive = (m_TimerID <> 0) End Property Private Sub TimerEvent() If UserForm1.Label2.Tag = "" Then UserForm1.Label2.Tag = 0 UserForm1.Label2.Tag = CLng(UserForm1.Label2.Tag) + 1 UserForm1.Label2.Caption = "Increment : " & UserForm1.Label2.Tag End Sub 

这在USERFORM

 Option Explicit Private Sub Label1_MouseDown(ByVal Button As Integer, _ ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single) StartTimer 200 'millisecond update End Sub Private Sub Label1_MouseUp(ByVal Button As Integer, _ ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single) StopTimer End Sub