Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: Visual Basic
Expertise: Intermediate
Aug 1, 1997

Trapping a Double Click for a Toolbar Button

VB4 supports the built-in Win95 Toolbar control, which allows users to add Buttons to the toolbar. The button has a ButtonClick event, but if you want to trap a double-click, there is no ButtonDoubleClick event. To work around this problem, declare two form level variables:
 
Private mbSingleClicked As Boolean
Private mbDoubleClicked As Boolean

        In the Toolbars ButtonClick event, add this code:

Private Sub Toolbar1_ButtonClick_
        (ByVal Button As Button)
Dim t As Single
t = Timer
If mbSingleClicked = True Then
        mbDoubleClicked = True
        MsgBox "Double Clicked"
Else
        mbSingleClicked = True
        ' allow the user to click the next 
        ' time if he wants to double click
        Do While Timer - t < 1 And mbSingleClicked = True
                DoEvents
        Loop
        ' if the user has selected a double 
        ' click end the sub.
        If mbDoubleClicked = True Then
                mbSingleClicked = False
                mbDoubleClicked = False
                Exit Sub
        End If
End If
If mbDoubleClicked = False Then 
        MsgBox "Single Clicked"
End If

'you can do the processings here, e.g
'If mbDoubleClicked Then
'--------- code
'ElseIf mbSingleClicked Then
'--------- code
'End If

'when exiting from the sub please 
'reintialize the variables, otherwise we 
'will end up with the single clicks only
If mbDoubleClicked = False Then
        mbSingleClicked = False
        mbDoubleClicked = False
End If
End Sub
Sushrut Nawathe
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date