I have made a custom LevelSlider (sub-class of Slider)
managed to add a new integer property called Level
in the ValueChange event I update Level
I also write to Level from elsewhere
I now want to add an event LevelChange so when you write to Level, the event fires
all seems to be there, but the event doesn’t fire
[quote=92626:@Markus Winter]Level should be a computed property then, and in its Set method you have to call the event with RaiseEvent LevelChange
But why don’t you use the ValueChanged event in the first place? Seems like unnecessary (and confusing) duplication of functionality to me.[/quote]
I have a separate property because windows shows vertical sliders upside down!
OSX shows it correctly
I want to have one property that I can use (Level) which is always the right way sense, and let the control worry about the niceties of display!
you lost me at
a) computed property
b) set method
I understand the concepts, just not sure where to find these things
thanks
aha
two clicks later I found computed property
and get/set
thanks!
hmm
I added RaiseEvent, but event still doesn’t fire when I change the value of Level, either explicitly, or by sliding the slider
bugrit
put code in the wrong place
standby!
Function changeLevel(newlevel as integer) As integer
#If targetWin32 then
slider1.value = slider1.maximum-newLevel
#Elseif TargetMacOS then
slider1.Value = newLevel
#Endif
Level = newLevel
return Level
End Function
In Slider1
Sub ValueChanged()
#If targetWin32 then
Level = me.maximum-me.value
#Elseif TargetMacOS then
Level = me.value
#Endif
End Sub
You never touch Value, and use changeLevel() to get or set Level.
Michel, if I’m not mistaken then in your changeLevel function you’ll always get the same value out that you put in: you put newLevel in, set level to newLevel, return level.
Not necessarily. When the user moves the slider, he changes Value, and in ValueChanged, Level is modified as well. The idea of changeLevel is never to get or set Level directly.
I put this together very quickly but Extend would probably allow a much simpler approcha akin to regular control properties.
It is no point to have this method return a value, as Level can be read directly.
Hence ChangeLevel should instead be used only to change the value of Level in order to have value modified accordingly :
Sub changeLevel(newlevel as integer)
#If targetWin32 then
slider1.value = slider1.maximum-newLevel
#Elseif TargetMacOS then
slider1.Value = newLevel
#Endif
Level = newLevel
End Function
Level could be used as a changeable property by using instead a timer which monitors its value and modifies the slider Value property accordingly in case it changes. Then a flag should be used in ValueChanged to prevent circular references when the user modifies directly the Value property by moving the slider knob.
I should probably study Extends to come up with a simpler solution, where a sub can act as a control property. At this time, I have not yet experimented with that command.
[quote=92625:@Mike McPherson]I have made a custom LevelSlider (sub-class of Slider)
managed to add a new integer property called Level
in the ValueChange event I update Level
I also write to Level from elsewhere
I now want to add an event LevelChange so when you write to Level, the event fires
all seems to be there, but the event doesn’t fire[/quote]
Use a timer to monitor Level and trigger LevelChange.