Click here to Skip to main content
12,888,825 members (49,526 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


7 bookmarked
Posted 23 Sep 2013

Click or DoubleClick

, 24 Sep 2013 CPOL
Rate this:
Please Sign up or sign in to vote.
This code processes a Click or a DoubleClick event.


I wanted to have a control that will process a Click event or a DoubleClick event.  All the solutions I could find on the internet used a rather complicated rollback process.  This is a very simple solution that could be understood by just about anybody.

Using the code

The form uses a label for the control. Just Click or DoubleClick on the label to try it out.  The code has a constant to enable the DoubleClick speed to be altered. 

Public Class frmClickDoubleClick

  Const DOUBLE_CLICK_SPEED As Integer = 250   'mouse DoubleClick speed
  Dim isDoubleTriggered As Boolean = False

  Private Sub labLabel_Click(ByVal sender As Object, _
          ByVal e As System.EventArgs) Handles labLabel.Click
    'delay (250ms) to make sure the DoubleClick code triggers first

    If isDoubleTriggered Then
    'if DoubleClick event triggered then supress the SingleClick code
      isDoubleTriggered = False
      'reset the DoubleClick flag
      Exit Sub
    End If

    Me.BackColor = Color.Coral              'SingleClick code
    Me.Text = "Single Click"
  End Sub

  Private Sub labLabel_DoubleClick(ByVal sender As Object, _
              ByVal e As System.EventArgs) Handles labLabel.DoubleClick
    isDoubleTriggered = True                   'flag the DoubleClick event
    Me.BackColor = Color.Aquamarine            'DoubleClick code
    Me.Text = "Double Click"
  End Sub

End Class 


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Systems Engineer
New Zealand New Zealand
No Biography provided

You may also be interested in...

Comments and Discussions

QuestionWhat about getting MouseEventArgs? Pin
Member 988791128-Nov-16 21:19
memberMember 988791128-Nov-16 21:19 
GeneralMy vote of 5 Pin
Carlos190724-Sep-13 0:54
memberCarlos190724-Sep-13 0:54 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170424.1 | Last Updated 24 Sep 2013
Article Copyright 2013 by terry.corridan
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid