How to separate click from doubleclick ?

Started by krunch, February 16, 2011, 01:49:22 AM

Previous topic - Next topic

krunch

Hi
I have a PictureBox that reacts to click and doubleclick by doing 2 differents things, but the OnClick event is always triggered before OnDblClicked (same for OnMouseDown and OnMouseDblClick)...
How do you prevent OnClick when OnDblClicked ??

Fred Tomke

Hi, that's right, OnDoubleClick means automatically that OnClick was fired before (same in all other controls and AFAIK in all other programming languages).
Please have a look at MouseMove - it also will be called at OnClicked. So maybe you can check the time between two clicks.

Regards
Fred
Fred Tomke
Dipl.-Ing. (FH) Landespflege

[ landscaper - landscape developer - digital landscape and urban design]

krunch

Hi

Thanks.. if I include onMouseMove the sequences I get are :
- clic : (m) c m
- dbleclic : (m) c m d c c m

where : m = onMouseMove (+ a first (m) if the control hadn't focus) / c = onClicked / d = onDoubleClick

Not simple... :-(

I'll search how to use TIMER in these sequences, but meanwhile if someone has already made that...

krunch

Hi
I've tried something with dcl_DelayedInvoke... but this function has many inconvenients : can't prevent the command name on the command line (?) and especially the command became the last one in the interface, user accessible..
Please do you confirm that's a wrong way ?

Code (autolisp) Select
(defun c:Untitled_Form1_PictureBox1_OnClicked (/)
  (setvar "CMDECHO" 0) ; no ?
  (setvar "NOMUTT" 1)
  (or *double (dcl_DelayedInvoke 350 "Do"))
)
(defun c:Untitled_Form1_PictureBox1_OnDblClicked (/)
  (setq *double T)
)
(defun c:Do ()
  (if *double (princ "\nClicClic!") (princ "\nClic!"))
  (setq *double nil)
  (setvar "CMDECHO" 1)
  (setvar "NOMUTT" 0)
  (princ)
)

owenwengerd

I think you are fighting a losing battle, and you should change your design instead.
Owen Wengerd (Outside The Box) / ManuSoft

Fred Tomke

#5
Hi krunch,

Maybe we should focus on WHY it is necessary to separate OnClick from OnDblClick. Maybe there are other solutions for that.

An (very up-to-date) example: I have a list view. When I click on an item, OnClick will be called and immediately the event function takes a look into a database with a complex query and shows the result in a grid (!!!) below the listview. Works fine. But clearing the grid, executing the SQL command and refilling the grid takes a recognizeble amount of time. So when I doublick an item, a subform has to be shown. But since OnClicked is fired, too, before OnDblClicked could be fired, the time is over that Windows could recognize my double click as a double click and it accepts it for two single clicks  >:( That's why I introduced a intLastClick variable to store the latestly selected listview item to leave the content of OnClick event out and finally Windows recognizes my double click as a double click.

So that's why I think we should talk about what you're trying to do and maybe we'll find a solution.

Regards,
Fred

[EDIT] Owen said the sentence of my post in a much shorter way :)
Fred Tomke
Dipl.-Ing. (FH) Landespflege

[ landscaper - landscape developer - digital landscape and urban design]

krunch

Hi, thanks for your answers

Yes, that the same problem : OnClick triggers before OnDoubleClick and make unwanted result, that's why I start from triggers order..

So, what I make is a "button" (a PictureBox indeed) that inverse(-) on click / erase a value onDoubleClick... the value is in a textbox, the button is before (contiguous) the textbox.. simple!
The problem is not only "esthetic" (the fact that I see "-" for a split second before the value is erased), because some textboxes must receive "1" instead of "" (erase) on doubleclick (scale factor).. so in that case I get "-1" and not "1"..
So I think I have to separate the 2 events

Hoping to have been explicit..
Regards

Fred Tomke

Hm, krunch, I wanna play around with that. Would you be so kind to create a small example to demonstrate? Maybe with only the image (as button) and the textbox. Thing what I cannot imagine, is, that I don't believe that the customer is familiar with that procedure. But maybe I would change my mind if I "feel" it by myself. by default I'd use 2 different buttons for two different actions. Or you devide the image in the left area and the right area ...

Regards,
Fred
Fred Tomke
Dipl.-Ing. (FH) Landespflege

[ landscaper - landscape developer - digital landscape and urban design]

krunch

#8
Hi

Sure!.. I made a simplified sample..

I precise that :

It's for this project (end of the page), so there's not 2 but 9 textboxes (may be +3 for columns), and when you click or doubleclick it updates the transformation...
The buttons (which will be more discrete and small) are placed in front of each textbox, and I manage inputs with my "Get_ControlName" function (btw I've also made a feature request here)

QuoteThing what I cannot imagine, is, that I don't believe that the customer is familiar with that procedure
As I try it I think it's really easy to adopt..

Thanks for interest
Regards

krunch

Ok I think I give up..  :(
According to the sequences there's no perfect way. I could wait at the next OnMouseMove afer OnClicked-OnMouseMove but it means that a simple click is "validated" by this next OnMouseMove, so it's triggered only when I move after click..

I think I will make a button divided into 2 parts (+/- up and reset down)...  or maybe right-clic for reset / left-clic for inverse (+/-) ?

Thanks


krunch

#10
Please do you confirm there's now way for the particularity of dcl_DelayedInvoke (can't prevent the command name on the command line (?) and especially the command became the last one in the interface, user accessible..) and no way to DelayedInvoke a standart function (not c:) ? Thanks in advance

Fred Tomke

Hi, krunch, sorry, I haven't seen your sample yet. I'll try it later this evening.

Fred
Fred Tomke
Dipl.-Ing. (FH) Landespflege

[ landscaper - landscape developer - digital landscape and urban design]

Fred Tomke

Hello, krunch,

hm, have you ever thought about right click on the imagebutton?

On the other hand I've found out that OnClicked will be fired twice so I hope Owen could pay attention to this topic again. :)

I've changed your sample and I attached it again. When you doubleclick an imagebutton, you can see the following lines in the command line.

PictureBox1_OnClicked
PictureBox1_OnDblClicked
PictureBox1_OnClicked


I'm not sure whether this behaviour is wanted. Maybe Owen can light up this for us.
I'll recommend you to use two different buttons for two different things - otherwise you will have to fight battles with your customers. I mean discussions about usability.

Regards,

Fred
Fred Tomke
Dipl.-Ing. (FH) Landespflege

[ landscaper - landscape developer - digital landscape and urban design]

krunch

Yes I came to the same conclusion : when DoubleClicked there's no way to prevent the 1st OnClicked event.. except with a delayed device, but DelayedInvoke operates as an AutoCad command, so it's no good  :(

Thanks Fred

owenwengerd

Fred, I'm not sure what exactly I'm supposed to test to reproduce this. Can you attach sample files in a new reply?
Owen Wengerd (Outside The Box) / ManuSoft