In Web Apps, we use Image Wells as buttons. We use the mousedown event as the “Action event”. We noticed that, if we double or triple click fast enough our "Image Well Button, the action is executed as many times as I click on the button… Every click is recorded…
Has anyone noticed that or found a way to avoid such a behavior? I though of using a ‘triggered’ property to eliminate repeated actions.
Don’t use MouseDown anyway. Use MouseUp instead, and verify that the mouse is inside the control before doing the action. That is the way normal buttons work. So if the user has a remorse and does not actually want to validate the push, he slides off the button and when he releases the mouse the action does not take place.
I finally solved this issue by following your advice and reading some older posts relative to identifying the cursor position…
I kept my button actions in Mouse Down since I did not figure out how to make Mouse Up active only while over the Webimageview.
Should I verify if the X And Y values are in a specific range? Something like : If X >= Me.Left And X <= Me.Left + Me.Width... There must be something more … elegant…
So I focused on retarding a little while the responsiveness of my button.
Here what I did :
1- added a timer (as a proprety of a Class ) that is initialized in the “constructor” at the opening of the session
//Paramtrage du timer de dsactivation temporaire des boutons
buttonTimer = New Xojo.Core.Timer
buttonTimer.Period = 1500
buttonTimer.Mode = xojo.Core.Timer.Modes.Off
AddHandler buttonTimer.Action, AddressOf buttonTimerAction
2- added a Boolean property to that same Class called "buttonWaiting"
3- added this handler method (buttonTimerAction) in that same Class
buttonWaiting = False
4- added this code to my button in MouseDown Event (Until I know how to use Mouse Up )
If Not buttonWaiting Then
buttonWaiting = True
buttonTimer.Mode = xojo.Core.Timer.Modes.Single
// bla bla bla .....
End If
If there is any way I can improve this, let me know…
There is another way I often use when something “stutters”. I do that for instance in a search field that works like the IDE’s. Each time keydown happens, it does not fire. But half a second after the last character has been punched, search happens.
buttonTimer = New Xojo.Core.Timer
buttonTimer.Period = 500
buttonTimer.Mode = xojo.Core.Timer.Modes.Off
Note the much shorter period. I assume the button clicks at a rapid pace
Then put the code for the button Action in the Action event of the timer.
The way it works, each time mouseDown clicks, it restarts the time, so Action does not fire. When there is no more MOuseDown, then the timer fires and Action executes.