Flickerfree graphics the easy way

My colleague Frits Ankersmit at Class-A just pointed me to a way to get flicker-free Windows applications in .NET for virtually free. Normally you would introduce a programmatic way to do double buffering, where you build the next image of a user drawn part of the window in memory. This requires quite a lot of coding and a (maybe considerable) amount of memory for a bitmap. The .NET Framework offers you to do all of this using memory from the videocard and handle all of the double buffering. Here’s how:

Enter the following line in the constructor of your form that does some animated drawing:

base.SetStyle(ControlStyles.DoubleBuffer | ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint, true);

That’s it. Have fun with it.

Advertisements
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s