Anonymous12321232

Hi,

i still have problem with the double buffer for a panel control. what i did is the following:

first i create a new class derived from panel and set the
control styles in the constructor, as shown below:

Code Snippet

public class DoubleBufferPanel : Panel

{

public DoubleBufferPanel()

{

// Set the value of the double-buffering style bits to true.

this.DoubleBuffered = true;

this.SetStyle(ControlStyles.AllPaintingInWmPaint |

ControlStyles.UserPaint |

ControlStyles.OptimizedDoubleBuffer, true);

UpdateStyles();

}

}

I replace the System.Windows.Forms.Panel declaration with the 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();

However, when i run this applications, an exception is thrown, sayiong "Parameter is not valid." , at this line of code
Application.Run(new Form1());

However, when I remove the code of DoublebufferPanel class: i.e. I remove the following code from it:

Code Snippet

// Set the value of the double-buffering style bits to true.

this.DoubleBuffered = true;

this.SetStyle(ControlStyles.AllPaintingInWmPaint |

ControlStyles.UserPaint |

ControlStyles.OptimizedDoubleBuffer, true);

UpdateStyles();

It works again, of course without double buffering. What i did wrong here please help.





Re: Windows Forms General C# panel double buffer

Karthik Krishnaswami

Very strange,I cant reproduce it.Can you try creating an empty form and drag and drop your new panel onto it and rebuild



Re: Windows Forms General C# panel double buffer

nobugz

It is not this code causing the exception. Setting DoubleBuffered to true is just equivalent to SetStyle(AllPaintingInWmPaint | OptimizedDoubleBuffer, true). Nothing wrong with SetStyle(). UpdateStyles() does nothing in the constructor.

When you get the exception, look at the StackTrace and post what's there.





Re: Windows Forms General C# panel double buffer

Anonymous12321232

Thank you all.

the error may be from other part of the code. i tested a simple program, it works. i remove the double buffer stuff, my program works too. so strange. i try to resolve it.