Programmatic Canvas Paint Event Handler

Working on a Mac Desktop application with latest Xojo. Most of my canvases are created in advance using the standard Layout editor, and as such it’s easy to add a paint event handler for such a canvas. But, what if in my program I dynamically at runtime add a bunch of new canvases, how/where do I specify the paint handler for those dynamically created canvases?

You can’t dynamically write the code, but… You could write the code in methods and use AddHandler to redirect the event.

I guess if you did need to dynamically write the code, you could duplicate the graphics commands in a xojoscript context and then run a script which returns a picture that you could then draw on the canvas. That’d probably work.

“AddHandler”!! Sounds like that’s the magic I was missing. Thanks Greg!