[.net] Double Buffering in GDI+

Started by
7 comments, last by DrGUI 18 years, 8 months ago
Is there class level support for double buffering in GDI+? I'm currently getting a graphics object from a bitmap, painting to that, and then painting the bitmap to the screen with the screen's graphics object, so it sort of suffices, but I'd like something a little more official. For example, in Java there is the BufferStrategy object, and you can create BufferStrategies (which also happen to be hardware accelerated) for any object below a comman java.awt.Window in the hiearchy. Just wondering if there is something similar for GDI+ (as so far GDI+ is pretty much a method-for-method copy of Java2D, which is okay with me).

[Formerly "capn_midnight". See some of my projects. Find me on twitter tumblr G+ Github.]

Advertisement
On the form properties, scroll down to "Double Buffer = false" and simply set it to true. Double buffering is now in session, and you don't have to do anything else to make it happen. You don't have to draw to the double buffer, for example. It does it for you.
uhmm, that wouldn't be .net 2.0, would it? I'm using .net 1.1 and I don't see it anywhere.

[Edited by - capn_midnight on July 31, 2005 3:10:06 PM]

[Formerly "capn_midnight". See some of my projects. Find me on twitter tumblr G+ Github.]

In your control/form's constructor put the following code:

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


Then do your drawing in an overriden OnPaint() method. If you need to constantly redraw, call Invalidate() at the end of OnPaint().
I've already ready slammed the plastic world through the loop to the girl in the fire. If you don't hold your colour, the sounds of life will beckon you to the terminal, by which time, you'll definately be out there.
Or (to constantly redraw) call Invalidate() from a Timer object to lock the framerate.

I was also looking for GDI+ double buffering techniques just before I noticed this thread.

Thanks guys.
I am a signature anti-virus. Don't spread me. I must die in peace.
If you're using a standard control, you can set DoubleBuffered = true from a derived class (it's a protected property).
Quote:Original post by CSharp_Padawan
Or (to constantly redraw) call Invalidate() from a Timer object to lock the framerate.

I was also looking for GDI+ double buffering techniques just before I noticed this thread.

Thanks guys.


Does anyone know what happens if the system can't keep up and the timer event is executing faster than the paint function?
I've already ready slammed the plastic world through the loop to the girl in the fire. If you don't hold your colour, the sounds of life will beckon you to the terminal, by which time, you'll definately be out there.
Quote:Original post by jystic
Quote:Original post by CSharp_Padawan
Or (to constantly redraw) call Invalidate() from a Timer object to lock the framerate.

I was also looking for GDI+ double buffering techniques just before I noticed this thread.

Thanks guys.


Does anyone know what happens if the system can't keep up and the timer event is executing faster than the paint function?

then you'll only see everything at the paint method's rate. Without dobule buffering, you see a defect called tearing, in which half of the next frame is partially covering the current frame.

[Formerly "capn_midnight". See some of my projects. Find me on twitter tumblr G+ Github.]

Also, don't forget to call Updatestyles (well it said that on teh intranet)

Setstyle(Controlstyles.DoubleBuffer | Controlstyles.UserPaint | Controlstyles.AllPaintingInWmPaint, true);Updatestyles();

This topic is closed to new replies.

Advertisement