Results 1 to 7 of 7

Thread: while mouse button is held down...?

  1. #1
    Guest
    I want an action to repeat while the left mouse button is held down over an image box (like the way that you hold rewind on media player and it rewinds). Does anyone know how i would do this?

  2. #2
    Guest
    Code:
    Private Sub Image1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
        If Button = 1 Then Print "Rewinding..."
    End Sub

  3. #3
    Guest
    Actually, that will not continuously repeat the event. If you want to do so then use this code instead.

    Add to a form with a Timer and an Image.
    Code:
    Private Sub Form_Load()
        Timer1.Interval = 100
        Timer1.Enabled = False
    End Sub
    
    Private Sub Image1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
        If Button = 1 Then Timer1.Enabled = True
    End Sub
    
    Private Sub Image1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
        If Button = 1 Then Timer1.Enabled = False
    End Sub
    
    Private Sub Timer1_Timer()
        Print "Rewinding..."
    End Sub

  4. #4
    Guest
    Thanks a lot it worked great!

  5. #5
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Here's another method you could use, wihtout having to use a timer control, so you can have more control over the "rewinding" processs...
    Code:
    Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
    
    Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
        Do While GetAsyncKeyState(1)
            Caption = "Rewinding"
            'do your rewinding here
            DoEvents
        Loop
        Caption = "Paused"
    End Sub
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  6. #6
    Guest
    I wondered if there were any activex controls or anything which make cool buttons like office toolbars (if you know what i mean)

  7. #7
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    go look at my homepage
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

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