Double Buffering on forms

J

Jason

I have created a 2d isometric game map using tiles and now I'm trying to
move around my map..when i go near the edge of the map I want to redraw the
map to show new parts of the map however the screen flicker a good bit while
this happens. I'm using GDI+ and it say in MSDN that double buffering will
fix this but it didnt work for me.

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

I set double buffering on the form, but I wonder if the problem is that I'm
using a panel control to do all my GDI + drawing in. When I set double
buffering on a form does that include all object on the form(ie my panel). I
cant set double buffer on a panel( i tired).

What else could cause this flicker? Any ideas?

Thanks
Jason
 
B

Bob Powell [MVP]

Setting double-bufferring on the form will not affect the components hosted
by the form. Panel does not double-buffer by default so my advise would be
to derive a class from Panel and turn on double-buffering in the constructor
of that class.

If you're drawing in response to the Panel's Paint event then you can either
move you code to the derived classes OnPaint protected method or respond to
that objects Paint event.

--
Bob Powell [MVP]
Visual C#, System.Drawing

The Image Transition Library wraps up and LED style instrumentation is
available in the June of Well Formed for C# or VB programmers
http://www.bobpowell.net/currentissue.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/gdiplus_faq.htm

The GDI+ FAQ RSS feed: http://www.bobpowell.net/faqfeed.xml
Windows Forms Tips and Tricks RSS: http://www.bobpowell.net/tipstricks.xml
Bob's Blog: http://bobpowelldotnet.blogspot.com/atom.xml
 
J

Jason

I created a class called ControlMap that is derived from Control?
I left my GDI+ code in the function Paint method. Double Buffering is
working fine this way.

My new question is regarding OnKeyUp and OnKeyDown and OnKeyPress events
that are registered to the main form of the app. Before I created this
ControlMap class I was able to use the arrow keys to move around my Map, but
after creating my controlMap class the OnKeyUp and OnKeyDown events never
get raised, but it seems strange to me because the OnKeyPress event still
works fine.

Any ideas? Did you intend for me to derive from Control class or a different
class.
Thanks for the help.

Jason
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top