How do you refresh a canvas after changing colours

Hi folks.
I’m still trying to get my head around Xojo and I guess my question relates to something pretty fundamental that I’ve overlooked.
In a window I have a canvas (Canvas1) with a background colour and coloured text. I have been playing around with the ColorPicker exemple here :
https://docs.xojo.com/GettingStarted:Creating_a_Color_Selector_Control
I have implemented it pretty much to the letter and added two instances of the ColorSelector to my window, one for the font colour, the other for the background… no problem up to there… I can pick colours in either of these. The problem is to apply them to the canvas.
As a temporary solution, I created a method “RefreshCanvas” and call it from a “MouseDown” event in the canvas. This works just fine too, but I’d like the canvas to be updated as soon as the colour is chosen in the ColorSelector. Ideally, the ColorPicker would be closed automatically as well (I can always dream!). On Macs running Big Sur, the ColorPicker has no close button, just a tiny close box in the top lefthand corner of the window.
My RefreshWall method code is simply :

BgCol = SelBgCol.SelectedColor
FontCol = SelFontCol.SelectedColor
Canvas1.Refresh(False)

BgCol and FontCol are variables in the Paint event of my canvas.SelBgCol and SelFontCol are my two instances of ColorSelector.

Can this be triggered automatically from some sort of event in the ColorSelector or elsewhere ?

Thanks for any help you can give a beginner :+1:

window.invalidate instead of canvas.refresh maybe

you would subclass this canvas and then add a computed property BgCol as Color
Canvas1.BgCol = SelBgCol.SelectedColor

in this computed property
you memory the color
mBgCol = BgCol
and use .Invalidate
in the canvas Paint Event you use this mBgCol to fill the canvas

i don’t know a instant event if color whas choosen.

colorpicker only have a ColorSelected event/method

Thank you both for your answers.
@ Per Ronny Westereng - It’s not that Canvas.Refresh doesn’t work. I’d just like to be able to call it automatically when the colour has been chosen.

@MarkusR - I’m not sure if my beginner knowledge is going to be able to handle that, but I’ll certainly give it a shot. ColorSelected would have seemed perfect, but I don’t see this event. Where is it hidden ?

this event is from new color picker in xojo 2021.
in ide/library it should appear beside datetime picker.

Ahhh… that explains it ! I need to upgrade… I’m on 2020 :+1:

not necessary just for a “new” color picker :wink:

Yes. It’s probably a bit of an overkill, just for that ! I’ll see if I can figure out your suggestion, if not, it’ll just stay at “Click on the canvas to refresh” !
Thanks again for your help.

Forum for Xojo Programming Language and IDE. Copyright © 2021 Xojo, Inc.