自定义控件中的双缓冲子控件(C#)
我想对包含按钮的自定义控件进行双缓冲。 我尝试了各种方法来双缓冲控件; SetStyle、BufferedGraphicsContext 和绘制位图。 这些对于控件的自定义绘制都工作得很好,但是它们都不能处理将按钮绘制到后台缓冲区。 我该如何实现这一目标?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
从技术上讲,您不能,而且如果它们是标准 .NET WinForms 按钮,您实际上也不需要这样做。
按钮本身通过受保护的 DoubleBuffered 属性进行控制。 访问它的唯一方法是从 SWFButton 派生一个新类,并实现代码以在该类的实例上启用 DoubleBuffered 属性(我可能会在构造函数中执行此操作)。 最后,在窗体上使用该新类的对象而不是 SWFButton。
然而,据我记得,按钮纯粹是从 WinAPI 中提取的; 它们不是 GDI+。 因此,您不需要需要对它们的绘图进行双缓冲。 也就是说,我不知道您的使用场景,也不知道您的应用程序显示什么症状,所以我可能是错的。 :)
你可以考虑看看Pro .NET 2.0 Windows Forms and Custom Controls in C#。 所有这些都是根据那本书中的信息总结的。
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.