396,068 Members | 1,842 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 396,068 IT Pros & Developers. It's quick & easy.

Double buffering with panel control

Millennium Falcon
P: n/a
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.AllPaintingInW mPaint |
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
Nov 16 '05 #1
Share this Question
Share on Google+
2 Replies


Rodger Constandse
P: n/a
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.

--
Rodger Constandse

<http://www.SequenceDiagramEditor.com>
Sequence Diagram Editor - A quick and easy way to draw and edit sequence diagrams

Millennium Falcon wrote:
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.AllPaintingInW mPaint |
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

Nov 16 '05 #2

Millennium Falcon
P: n/a
I thank you very much Rodger. Your reply has resolved my problem.

Best regards

"Rodger Constandse" wrote:
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.

--
Rodger Constandse

<http://www.SequenceDiagramEditor.com>
Sequence Diagram Editor - A quick and easy way to draw and edit sequence diagrams

Millennium Falcon wrote:
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.AllPaintingInW mPaint |
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

Nov 16 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.