[.net] Double Buffering in GDI+
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).
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]
[Edited by - capn_midnight on July 31, 2005 3:10:06 PM]
In your control/form's constructor put the following code:
Then do your drawing in an overriden OnPaint() method. If you need to constantly redraw, call Invalidate() at the end of OnPaint().
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().
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 was also looking for GDI+ double buffering techniques just before I noticed this thread.
Thanks guys.
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?
Quote:Original post by jysticQuote: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.
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
Popular Topics
Advertisement