custom event confusion

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

what did I miss?
thanks

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=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 :slight_smile:
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!

Added to the window

Level As Integer

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.

No custom event here.

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.

I see that, but to simplify your code to the relevant portions:

So you put in NewLevel, set Level to NewLevel, and return Level. You will ALWAYS get the same value out that you put in.

You are right.

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.