Repainting a Canvas

I have a canvas on which I paint several items with a timer. Some move, some not.
I noticed that the Paint event wipes the Canvas - I mean I have to repaint the items that do not move? How do I keep these items on the canvas - they don’t need a repaint…

You can set a certain part of the canvas to be refreshed.

For example to only refresh the top left 100x100 rectangle:

canvas1.invalidate(0,0,100,100,false)

Draw the non-moving parts into a buffer image. In the Paint event, draw that first, then the moving parts on top of it.

Christoph: thanks. Didn’t know that, I look into it.

Tim: the Paint event fires about 10 times a second… your solution will not deal with the flicker I think (Windows, I noticed that already)…

I think Tim’s solution should work just fine, and is worth trying. Just make sure to set the DoubleBuffer property of the main canvas to True to prevent any flicker.

I’ve used this approach in many projects before without problems.

OK, I’m busy implementing that. Thanks.

Alexander, if you’re interested, Alain Bailleul is a guru with graphics, and here is an example project of his, where he does an amazing job of using buffers to create some awesome animated effects.

Download Project

I’ve learned a lot about 2D graphics animation by working through this code… geniet dit :wink:

Daar geniet ik zeker van!

Wow… I will look into his code…