Invalidating Canvas in a outside class

Hi, i’m new in xojo. does anyone know how can i invalidate my canvas from another class?

Hi Amin,
You should have no trouble calling Invalidate on a canvas:

Canvas1.Invalidate( False )

What problem are you actually having?

this is great that u r answering my question. im trying to create an animator timer class. but i cant refresh the canvas in my timer class actully i cant pass it to my animator class

I actually did a 4-part series on the Xojo blog about building such animations:

something like ur animate canvas but more flexible
ive done it before in wxpython

actually i read it completely before. ur r using the action event in ur canvas
but my timer is a class inherited from timer that can change the objectvalues using easing time graphs

All of that can be easily decoupled from the canvas. My GraffitiAnimator for Desktop is a standalone class that provides updates that can be applied anywhere via events, for instance.

Alot of the code is the same, it’s just repackaged in a reusable manner. And there’s no shortage of built-in easing functions:

Great but i have done all this before and converted the python codes to Xojo.

OK, well, all you need to do is invalidate your canvas as your animation progresses. Not sure how else I can help, then.

my question is how can i invalidate this switchbutton canvas in animator class?

Well, you could pass it in as part of your animation operation when you start, make it a property of the animator class, or create an event definition for the animation progress that your Canvas component receives using AddHandler.

thanks a lot. but how can i pass it to animator when i try it like this i get nilexceptionerror
animator.MainParent = Me

You would set it to an instance of your Animator class. I assume you are creating an instance, so it should look something like this:

var myAnimator as new Animator '// If you don't create a new instance and are instead just declaring a variable or property, it will be nil.
myAnimator.MainParent = me
myAnimator.RunMode = Timer.RunModes.Multiple

i have done this all before but i get error. i defined a property of my animator class. should i use New for it in open event?

You could instantiate as needed, when you get ready to perform an operation:

if animator = Nil then
  animator = new Animator

You could do it in your Canvas subclass’ Opening event:

animator = new Animator

I’d encourage you to use a different name for your property, though.

1 Like

thanks alot… i should New it
.thanks for ur support and ur great article that helped me alot getting familiar with this kind of VB like coding

Happy to help! Please mark a solution so that others can easily find it in the future, should they need to.

1 Like