Double buffer a form

M

Martin Stenhoff

Is there some trick to double buffer a whole form without having to subclass
every single control on it to make each control double buffered?
I've noticed that when I resize my form the controls on it starts flicking
so much it's not even funny.

I thought I could be clever and do something like this

foreach(Control c in this.Controls){
// Set the value of the double-buffering style bits to true.
c.SetStyle(ControlStyles.DoubleBuffer, true);
}

but that won't work since the SetStyle method is declared as protected in
Control. (Why is it declared protected?)

Martin
 
B

Bob Powell [MVP]

Because all controls on a form are autonomous windows double bufferng the
form has no effect on the flickering of the controls.

The short answer is no. You may however like to look at options such as
suspending layout for a short time while resizing is going on.

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

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

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

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.
 
M

Martin Stenhoff

Yeah I noticed that making a form double buffered has not impact on the
child controls.

But is there a good reason for not being able to call Control.SetStyle()
from outside the
Control class?

Martin
 
B

Bob Powell [MVP]

I suppose that from a class design point of view the style was made
protected so that external classes couldn't fundamentally change the drawing
system without the control providing a specific mechanism for doing so.

Those styles can have far-reaching consequences for drawing and mouse input.

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

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

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

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.
 

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