Results 1 to 4 of 4

Thread: Auto Decrement while mousedown

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 1999
    Location
    Burlington, IA, USA`
    Posts
    77
    How to do something while mousedown is true

    example: Decrement the year while a label mousedown event is true, & stop decrement after releasing the mouse button
    An ass may bray a good long time before he shakes the stars down.
    T.S. Elliot

  2. #2
    Member
    Join Date
    Dec 2000
    Posts
    37

    MouseUp event

    Place a timer at your form. set the clock to execute the decrement every, say, 1 sec, by seting it's Interval property to 1000 (ms).

    Now disable the timer at designtime and add these events:

    Code:
    Private Sub Label1_MouseDown(....)
         Timer1.Enabled = True
    End Sub
    
    Private Sub Label1_MouseUp(....)
         Timer1.Enabled = False
    End Sub
    
    Private Sub Timer1_Timer()
         count = count - 1
    End Sub
    Code:
    Dim yosef as Programmer
    more.list.AddItem "Java", vbMore
    yosef.AddList("VB", "C++", "Pascal", more.list)

  3. #3
    PowerPoster Chris's Avatar
    Join Date
    Jan 1999
    Location
    K-PAX
    Posts
    3,238
    yosef, I don't think we really need a Timer for this simple task. If you affraid the Label1.Caption change too fast, then you can perform a delay by calling the Sleep API like what I've did.

    Code:
    Option Explicit
    Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
    
    Private IsMouseDown As Boolean
    
    Private Sub Form_Load()
    IsMouseDown = False
    End Sub
    
    Private Sub Label1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    IsMouseDown = True
    Do While IsMouseDown
        Label1.Caption = Val(Label1.Caption) - 1
        Sleep 250 'delay 250ms
        DoEvents
    Loop
    End Sub
    
    Private Sub Label1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
    IsMouseDown = False
    End Sub

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Jan 1999
    Location
    Burlington, IA, USA`
    Posts
    77
    Chris
    Your solution works well with slight modification in my app
    without the overhead of a timer.

    Thanks
    An ass may bray a good long time before he shakes the stars down.
    T.S. Elliot

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width