Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Button double click

Status
Not open for further replies.

Kenny62

Programmer
Mar 3, 2004
54
GB
I have a event handler for a command button double click event. When the app runs - the code in the event handler never gets executed. Why? I've had a look at the MSDN help and the double click event is not listed for a command button - however it is available from the drop down list. Is there a workaround to get double click to work . If so, how.

Thanks for your help in advance.
 
Well, here is a work around I found.

Declare a public integer.
Put a timer on the form set it to enabled and make the interval 500 (half a second).
The timer's tick event should set the integer to 0.
On the click event for the button place code like the following:
Code:
If x = 1 Then
  MsgBox("Double click")
End If
x += 1

The timer resets the integer every half second, so when you click the button fast enough - you should be able to get it while the integer is 1 (double click).

Hope that helps.
 
Thanks for the reply - unfortunately this method is unreliable - however it gave me the ideas how to code it cleaner. (Double click event get handled only when they fall within the timer window - this is a hit and miss affair).

The solution that i've adopted is as follows:

Private m_ThisButton As Object

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click

If Not Timer1.Enabled Then
m_ThisButton = sender
Timer1.Enabled = True
'Do click stuff

_Button3_Click(sender, e)
Exit Sub
End If
If Timer1.Enabled And (m_ThisButton Is sender) Then

Timer1.Enabled = False
Button3_DoubleClick(sender, e)
End If

End Sub

Private Sub _Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Debug.WriteLine("Button3_Click")

End Sub

Private Sub Button3_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs)
Debug.WriteLine("Button3_DoubleClick")

End Sub

Private Sub Timer1_Tick(byval sender as object, byval e as system.eventargs) handles timer1.tick

timer1.enabled=false
end sub

Here the timer is enabled in the button click event, also we save the sender - this button. On the second button click - if the timer is still enabled - then this is a double click event - call sub for double click.
Note timer interval is 500 ms.

Ken
 
If a button doesn't raise a double-click event (I wouldn't know, I've never tried it), then your best option, IMO would be to use a control that does raise one. You can even make a user control, and make it look like a button. It does not surprise me that a button does not raise this event, because, by nature, when one sees a button in Microsoft Windows, he or she is traditionally to expect something to occur when it is clicked just once.
 
Your right with regard to what you expect a button to do - however, i'm writing a touch screen application and need a method to play an audio clip when the button is clicked and another methed to action the button. Hence the need for double click event support. Not the most elegant interface - that it what the users want.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top