1

フォームに 2 つのラベルがあります

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

更新:クリックが押された場合、インクリメントを維持したいことがわかりました。私が考えることができる唯一の方法は、タイマーイベントを再トリガーする厄介な「ハック」です。オブジェクト名を更新する必要がUserform1ありLabel1、64 ビット用Label2に調整する必要がある場合がありPrivate Declare Functionます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
于 2012-08-29T09:33:34.940 に答える