Double click event

I need to have some code triggered when the user
double clicks on a label control.

How do I do that? I think MouseDown is just single click.

Set up a property named lastClick.
On the mousedown event subtract the current ticks from the lastClick value.
If the difference is within some threshold execute the double click code and update the lastClick property.

Or use a canvas and take advantage of the DoubleClick event.

You could actually place the canvas on top of the label and get the doubleclick event :slight_smile:

Technically, since a DoubleClick is not only timing dependent but the clicks must (should) take place within a small location variation, using a overlaying canvas and its DoubleClick event is probably the correct approach.

Double click is also defined in the Mouse preferences, in terms of speed. So it is far better not to fix an arbitrary time response simulation, but to rely on the actual DoubleClick event.

OK when I get a chance I will try this. Thanks.

I do that with an extend and use two methods.
The first method determines the double click interval in windows and/or macOS:

//-------------------------------------------------------------------------------
// determine the double click in macOs or Windows  
//-------------------------------------------------------------------------------
// <-- double click interval with unit TICKS
// ------------------------------------------------------------------------------
		
#if TargetMacOS
  Const CocoaLib As String = "Cocoa.framework"
  declare function NSClassFromString lib CocoaLib(aClassName as CFStringRef) as ptr
  declare function doubleClickInterval lib CocoaLib selector "doubleClickInterval" (aClass as ptr) as double
  try
	RefToClass = NSClassFromString("NSEvent")
	return doubleClickInterval(RefToClass) * 60
    catch err as ObjCException
	MsgBox err.message
  end
#endif
		
#if TargetWin32
  Declare Function GetDoubleClickTime Lib "User32.DLL" () as Integer
  try
	return GetDoubleClickTime()
    catch err as ObjCException
      msgbox err.message
  end
#endif
		
return 0

This method has the return type “integer”.

The second method determines the difference of time between the two clicks and the distance of the mouse pointer at time of the first click and at the time of the second click to decide the the two clicks might be a double click:

// ----------------------------------------------------------------------------------------------
// Enhancement of Control ComboBox for checking the double click
// ----------------------------------------------------------------------------------------------
// --> cb actual ComboBox
// --> x  actual X-Position of mouse pointer
// --> y  actual Y-Position of mouse pointer
// <-- logical value  double click Yes or No
// ----------------------------------------------------------------------------------------------
dim currentClickTicks as Integer
dim lv_DoppelKlick    as boolean = false
		
static lastVonClickTicks as integer
static lastVonClickX     as Integer
static lastVonClickY     as Integer
		
currentClickTicks = ticks
		
if not IsContextualClick then                                            'not a click with the right mouse key
  if (currentClickTicks - lastVonClickTicks) <= DoppelKlickIntervall then 'period of time is into the double click interval
    if abs(X - lastVonClickX) <= 5 and abs(Y - LastVonClickY) <= 5 then   'both Clicks are close together  
								
	lastVonClickTicks = currentClickTicks
	lastVonClickX = X
	lastVonClickY = Y
								
	lv_DoppelKlick = true
								
	end if
    end if
				
   lastVonClickTicks = currentClickTicks
   lastVonClickX = X
   lastVonClickY = Y
				
end if
		
Return lv_DoppelKlick

This method has the parameters “extends cb as ComboBox, x as integer, y as integer” and the return type “boolean”.

I use the double click extension into the MouseDown event of a combobox:

if me.DoppelKlick(x,y) then
				
	<do something>
				
end if

Sorry, into my source are some german expressions. I think you can enhance a label control also.