渐变面板中的闪烁
我从 TPanel 继承了一个控件,并在 Paint 事件处理程序中,我使用渐变绘制了整个客户端矩形。在用户调整大小之前,这工作得很好。 调整面板大小时,面板组件闪烁过多。
我怎样才能避免这种闪烁。我在MS Office 2007中看到了渐变,即使我们调整客户区的大小,也不会出现闪烁。请赐教我这一点。
感谢期待
I have inherited a control from TPanel and in the Paint event handler, I have drawn the entire client rect using a gradient. This works perfectly fine until the user resizes.
When the panel is resized, the panel component flickers too much.
How can i avoid this flicker. I saw the gradients in MS office 2007, even if we resize the client area, there will not be a flicker. Please enlighten me on this.
Thanks in anticipation
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可能想看看这个问题如何消除 TPaintBox 右边缘的闪烁(例如调整大小时)
很好地概述了避免闪烁以及 TPanel 的选项。
编辑 :
我在 Windows 7 上的 Delphi XE 版本中进行了快速测试。
使用此代码我无法重现任何闪烁。
继承的 Paint 被删除,Paint 例程相当快。
如果您仍然可以看到闪烁,则可以实施 Simon 的建议,但最好保留为组件本身的生命周期创建的位图。
You may want to look at this question How to eliminate the flicker on the right edge of TPaintBox (for example when resizing)
Good overview of options to avoid flicker and also for TPanel.
Edit :
I made a quick test in my Delphi XE version on windows 7.
With this code I cannot reproduce any flicker.
The inherited Paint is removed and the Paint routine is quite fast.
If you still can see flicker, the proposal from Simon can be implemented, but better keep the bitmap created for the lifetime of the component itself.
减少闪烁的一种方法是将渐变绘制到临时位图,然后将位图的全部内容绘制到面板。此方法假设您有一个 OnPaint 方法和一个可以在继承的面板中绘制的画布。
所以像这样(未经测试)
A way to reduce flicker is to draw the gradient to a temporary bitmap the draw the entire contents of the bitmap to the panel. This method assumes you have an OnPaint method and a canvas to draw on in your inherited panel.
So something like this (untested)