views:

1926

answers:

1

I want to double buffer a custom control which contains buttons. I have tried various ways to double buffer the control; SetStyle, BufferedGraphicsContext, and drawing to a bitmap. These all work fine for the custom drawing of the control, but none of them handle drawing the button to a back buffer. How do I achieve this?

+2  A: 

Technically you can't, and you really shouldn't need to if they're standard .NET WinForms buttons.

The buttons themselves control that through the protected DoubleBuffered property. The only way to access this would be to derive a new class from S.W.F.Button, and implement code to enable the DoubleBuffered property on instances of that class (I'd probably do that in the constructor). Finally, use objects of that new class on your form instead of S.W.F.Buttons.

However, as I recall, buttons are purely drawn from WinAPI; they are not GDI+. As a result, you shouldn't need to double-buffer their drawing. That said, I don't know your usage scenario and I don't know what symptoms your app is displaying, so I could be wrong. :)

You might consider checking out the book Pro .NET 2.0 Windows Forms and Custom Controls in C#. All of this was summarized from information in that book.

John Rudy