A slider question.

Hi! I’m stuck on this simple issue. I have a slider with this code in the ValueChanged event:

if slider1.Value = 0 then Label1.Text = "#" else Label1.Text = Chr(64+Slider1.Value) End If

When i move the slider, the label1 changes his value correctly but when i stop (AND ONLY IN THIS CASE) i want to fire an event.
How to do this?

Hello,

what do you mean with “when i stop (and only in this case)”?
When you release the Mousebutton? Or after a time when you do not change the slider?

  • Drag a timer to the window
  • Call it TimerSlider
  • Mode Off, Period 250
  • In ValueChanged, add :

TimerSlider.Mode = Timer.ModeOff TimerSlider.Mode = Timer.ModeSingle

When the slider is stopped, 250 ms later, the Action event of the timer is fired.

The way it works is in the valuechanged event, the timer is reset to off, and to single. As long as the slider is moved, the timer never gets to fire. If the slider is idle for over 249 ms, the event fires.

250 ms is a quarter a second. Unless the user is real slow, that value is pretty safe to fire when the user has stopped interacting.

Thank you, Michel, for your correct answer! It’s a complicated way but works!!!

For Marco: i mean when i release mouse button but if i insert a return true in the mousedown event to use the mouseup event, the slider not works!

A less complicated way would be to put the following inside the ValueChange event:

Xojo.Core.Timer.CancelCall(AddressOf DoThisLater) Xojo.Core.Timer.CallLater(250, AddressOf DoThisLater)

Then create a Method called DoThisLater which will be called when no Slider movement has taken place for 250ms.

No other timers need to be added to the window, nice and neat.

https://forum.xojo.com/50884-tip-narrowing-results-as-you-type

[quote=423818:@]
A less complicated way would be to put the following inside the ValueChange event:

Xojo.Core.Timer.CancelCall(AddressOf DoThisLater)
Xojo.Core.Timer.CallLater(250, AddressOf DoThisLater)[/quote]

I did not realize you could instantiate Xojo.Core.Timer from thin air like that.

Actually with such a technique, it renders it super easy to create a slider custom class with an EndMovement (or whatever name) custom event.

Thank you, Julian! It’s a very elegant solution!