Friday, 16 November 2007

Double Buffer Graphics in C# + GDI (II)

This happens sometimes to me.

As a C++ programmer, when I moved to .net I was not used to have things done there for me, so I tended to do everything on my own (I found myself once programming a method to search a substring inside a string... ;), and today it happened again.

Augusto Ruiz has left a comment in my last post about GDI DoubleBuffering that is worth to mention, because all the DoubleBuffer implementation I showed in the last post, can be overriden by a simple property of the control you are going to render in:

public class DoubleBufferedPanel : Panel
public DoubleBufferredPanel()
this.DoubleBuffered = true;

This property is inherited from Control, so any windows control has it, but is protected. Thats why you need to create a custom Panel, Button, or whatever you want to use as rendering target. Just change its value in the constructor and that´s it!

The previous implementation still has it´s advantages, like a full control on the rendering and presentation process, but for simple cases this way is muuuuuch simpler.

Can´t understand why a google on this topic shows CodeProject entries talking about a custom implementation like the previous one, and no one talks about this way. Probably because it´s too simple and everybody knows it... je je...


1 comment:

Anonymous said...

thanks ,you are a good man.