简体   繁体   English

自定义控件中的双缓冲子控件(C#)

[英]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. SetStyle,BufferedGraphicsContext和绘制到位图。 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? 我该如何实现这一目标?

Technically you can't, and you really shouldn't need to if they're standard .NET WinForms buttons. 从技术上讲,你不能,如果它们是标准的.NET WinForms按钮,你真的不应该这样做。

The buttons themselves control that through the protected DoubleBuffered property. 按钮本身通过受保护的DoubleBuffered属性控制它。 The only way to access this would be to derive a new class from SWFButton, and implement code to enable the DoubleBuffered property on instances of that class (I'd probably do that in the constructor). 访问它的唯一方法是从SWFButton派生一个新类,并实现代码以在该类的实例上启用DoubleBuffered属性(我可能在构造函数中这样做)。 Finally, use objects of that new class on your form instead of SWFButtons. 最后,在表单上使用该新类的对象而不是SWFButtons。

However, as I recall, buttons are purely drawn from WinAPI; 但是,我记得,按钮纯粹是从WinAPI中提取的; they are not GDI+. 他们不是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# . 您可以考虑在C#中查看Pro .NET 2.0 Windows窗体和自定义控件一书。 All of this was summarized from information in that book. 所有这些都是从该书中的信息中总结出来的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM