1

我的表格上有两个标签

lab01_Click:
lab02.Caption = lab02.Caption + 1

有没有办法将 lab01 用作旋转按钮?
如果我一直按下它 - 那么 lab02.Caption 应该不断变化吗?

4

1 回答 1

1

您也可以将数据存储在 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

更新:好的,我看到如果单击被按下,您希望保持递增。我能想到的唯一方法是重新触发计时器事件的令人讨厌的“黑客”。您将需要更新对象名称Userform1Label1并且Label2可能需要Private Declare Function针对Private Declare PtrSafe Function64 位进行调整

试试这个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
于 2012-08-29T09:33:34.940 回答