Double Click button

jmasgalas

Member
Joined
Apr 21, 2007
Messages
15
Programming Experience
Beginner
This is most likely very simple but I want to have a button require a double click instead of a single click. How do I do this? Thanks!
 
It is not that simple because it conflicts with default system behaviour. The ControlStyles.StandardDoubleClick bit have to be turned on which can only be done with the protected SetStyles method, this means you have to create an inherited Button control to make use of it. Here is how:
VB.NET:
    Sub AddNewDoubleClickButton()
        Dim b As New doubleclickbutton
        AddHandler b.DoubleClick, AddressOf Button_DoubleClick
        Me.Controls.Add(b)
    End Sub
 
    Class doubleclickbutton
        Inherits Button
        Public Sub New()
            SetStyle(ControlStyles.StandardClick, True)
            SetStyle(ControlStyles.StandardDoubleClick, True)
        End Sub
    End Class
 
    Private Sub Button_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs)
        MsgBox("double-click")
    End Sub
If you also attach the single-click event for this both events trigger when double-clicked. This mean you will loose the standard behaviour if you implement the double-click (it will not be an "additional" feature), thus breaking the system standard UI and may alianate your users. There is probably a good practise rule agaist doing this with standard controls.
 
Thanks Jugg but I am new so I need more explaining. If I just drag a button onto the form. Where do I change the event to a double click in the code?
 
Because this is how Windows operating system is built deep into the core, some of these features is called standard controls and the system handles much of the features and behaviour for these; like click of buttons, windows borders and title bars, textboxes appearance. The .Net Framework haven't rebuilt these control fully, but add to the standard ones, this also means the limitations of the core controls persist if layer can't provide workarounds.
 
Did you call AddNewDoubleClickButton ?
 
OK so now I am confused. How can I simple double click event be so hard?

Because it's a dumb idea. Everyone in the world, who ever used any GUI, expects a button to be a single click device. For example, what buttons on anything in your home (the microwave, the hifi, the tv) require two presses?

None of them.

It's bad HCI, just dont do it.
 
wut if i just change the handle of the button like:

Private Sub Button_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) handles button.doubleclick
MsgBox("double-click")
End Sub

won't that work ????
if not then why they added this event if it's going to conflict with the system standard behavior as u said ????
 
Back
Top