Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Double buffer child controls in custom control (C#)

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?

like image 410
Matt Borum Avatar asked Nov 05 '22 23:11

Matt Borum


1 Answers

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.

like image 104
John Rudy Avatar answered Nov 12 '22 10:11

John Rudy