Double buffering with panel control

G

Guest

Hi!

In my application, I have a panel in the middle of the form, which I'll be
using as a drawing panel. I would like to update the drawing panel each time
when it is required, without updating the form as a whole. The following
snippet makes compiler mad :

this.DXPanel.SetStyle(ControlStyles.AllPaintingInWmPaint |
ControlStyles.Opaque, true);

How can I apply double buffering to panel to update it (with its paint
method and
without flickers)?

Please respond in C#. I am new to C# and have no knowledge in VB.

Thanks for all the suggestion.
Regards
 
R

Rodger Constandse

Hello,

The problem is that the SetStyle method of the Control class is protected, which
is why the compiler is complaining.

It seems that you need to create a new class derived from Panel and set the
control styles in the constructor. Something like:

public class DoubleBufferPanel : Panel
{
public DoubleBufferPanel()
{
// Set the value of the double-buffering style bits to true.
this.SetStyle(ControlStyles.DoubleBuffer |
ControlStyles.UserPaint |
ControlStyles.AllPaintingInWmPaint,
true);

this.UpdateStyles();
}
}

You can then use this new class instead of your panel. Just replace the
System.Windows.Forms.Panel declaration with your DoubleBufferPanel where the
panel variable is declared and where the panel is created in InitializeComponent().

For example,

System.Windows.Forms.Panel panel1 becomes DoubleBufferPanel panel1

and

panel1 = new System.Windows.Forms.Panel(); becomes panel1 = new DoubleBufferPanel();

hope this helps.
 

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