CommandButtonの押しっぱなしの検出

タグの編集
投稿者 じょにー  (社会人) 投稿日時 2011/6/23 20:04:06
VB6を使っていますが、少し解らない、所が、あるので、どなたか、ご教授下さい。
現在やろうと、している事は、フォーム上に2つのCommandButtonが、配置してあり、それぞれが、増加と、減少の機能を持たせてありCOMMANDをクリックすると、数値が1づつ増減して長押しすると、10づつ、減少する。CommandButtonを作りたいのですが、この長押しの検出の仕方が解りません、そもそも、その様な事が、可能か、どうかも、解りません。是非、可能なら、ご教授お願いいたします。
投稿者 shu  (社会人) 投稿日時 2011/6/23 21:27:41
MouseDownで開始 -> Timerで処理 -> MouseUpで終了

という流れで考えれば良いと思います。
投稿者 魔界の仮面弁士  (社会人) 投稿日時 2011/6/23 21:39:27
> VB6を使っていますが、少し解らない、所が、あるので、どなたか、ご教授下さい。
『、』が多すぎて日本語として不自然です…。


> COMMANDをクリックすると、数値が1づつ増減して長押しすると、10づつ、減少する。
Option Explicit

Private IncrementValue As Integer
Private Const Interval1 As Integer = 800
Private Const Interval2 As Integer = 200
Private Const Interval3 As Integer = 55


Private Sub Form_Load()
    IncrementValue = 0
    Me.LabelValue = 100
    Me.Command1(0).Caption = "Up"
    Me.Command1(1).Caption = "Down"
End Sub

Private Sub Command1_MouseDown(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
    Increment Choose(Index + 1, 1, -1)   '+1 または -1 
    Timer1.Interval = Interval1
    Timer1.Enabled = True
    IncrementValue = Choose(Index + 1, 10, -10)   '+10 または -10 
End Sub

Private Sub Command1_MouseUp(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
    IncrementValue = 0
End Sub

Private Sub Timer1_Timer()
    Static Counter As Integer
    If IncrementValue = 0 Then
        Counter = 0
        Timer1.Enabled = False
        Exit Sub
    End If
    Counter = Counter + 1
    If Counter < 10 Then
        Timer1.Interval = Interval2
    Else
        Counter = 10
        Timer1.Interval = Interval3
    End If
    Increment IncrementValue
End Sub

Private Sub Increment(ByVal Value As Integer)
    Me.LabelValue = Me.LabelValue + Value
End Sub

Public Property Get LabelValue() As Integer
    LabelValue = CInt(Val(Label1.Caption))
End Property
Public Property Let LabelValue(ByVal Value As Integer)
    Label1.Caption = CStr(Value)
End Property
投稿者 じょにー  (社会人) 投稿日時 2011/6/23 23:34:59
魔界の仮面弁士様、いつもながら素早いご解説ありがとうございます。大変参考になりました、ありがとうございます。