I was experimenting with Canvas and now I know its possible. to make custom buttons with it.
But then I thought: Should be possible to make an animation with canvas??
I have in mind to make a Blinking cursor animation with tying text effect.
May be im in a error for use a “FOR NEXT” But I suppose I should start with these to test.
But When I put me.refresh on “Paint” Event. I got ran error.
When a canvas paint event is called, it is meant to give the canvas time to draw the appearance of its content for further display. You are basically trying to prolong that single timeslot to 2001 different refresh cycles. When you are calling a refresh from inside this event, you are causing that stack overflow. The canvas has not finished his drawing cycle but calls another one already.
Keeping in mind that the paint event is meant for 1 redraw, you could instead
Create a boolean in your window or as a BlinkingCanvas property if you go for a subclass that tells you if the current cursor state is visible or invisible.
In your paint event, check this boolean and draw your line (or not if its invisible)
install a timer with a rather high delay value (you want it to blink, not to flicker) that inverts the boolean and calls a canvas.invalidate.
EDIT:
[quote=250722:@Gerardo García]I was experimenting with Canvas and now I know its possible. to make custom buttons with it.
But then I thought: Should be possible to make an animation with canvas??
[/quote]
To answer that: Absolutely. You can consider a canvas, although it seems pretty advanced with all its events, as the most basic control representation of anything you see on screen. Which means a control like a button is basically a canvas that has a specialized paint event and is often a combination of several “canvases” (read it as NS/UIView on OS X and iOS) with some properties and methods attached to it a native control is very much like what you create when you subclass a canvas (or build a ContainerControl).
So yes, animations are absolutely possible. There may be limitations regarding the processing speed, but the Graphics draw routines are pretty fast. Just look at a game like Parallaxia that only uses an iOS Canvas.
This is a PERFECT place for a timer created solely in code and hooked up using AddHandler (rather than the zillion places AddHandler IS used)
Set the timers period to something like .3 seconds and on every execution draw it or erase it (track this state using a boolean)
The code editor does roughly this (with a lot more code to it but thats the basics)