在双缓冲TTreeView上自定义图形时闪烁

在双缓冲TTreeView上自定义图形时闪烁

本文介绍了在双缓冲TTreeView上自定义图形时闪烁的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以这种方式侦听TTreeView事件的AdvancedCustomDraw事件时:

When listening to the AdvancedCustomDraw event of a TTreeView event this way:

if Stage = cdPrePaint then begin
    // modify some Sender.Canvas properties and let it draw itself
end else if Stage = cdPostPaint then begin
    // draw 'something extra' using a separate TControlCanvas
    TControlCanvas.TextOut(SomeRect, 'Hello');
end;

...似乎当我启用DoubleBuffered时,控件决定不将多余的东西"复制到屏幕外缓冲区.这意味着只要我不打扰相关窗口,一切都很好.当我这样做时,多余的东西"仅在窗口的随机部分中可见.

... it seems that when I enable DoubleBuffered the control decides not to copy the 'something extra' to the offscreen buffer. This means that as long as I don't disturb the window in question, all is fine. When I do, the 'something extra' is only visible in random parts of the window.

我在这里想念什么?

推荐答案

由于您的评论让我全权以赴,提出了另一种解决方案,因此,我将这样做:

Since your comment gave me carte blanche to suggest an alternative solution, here's what I would do:

  1. 使用DoubleBuffered停止.它在许多控件中导致很多视觉上的怪异.我个人避免像瘟疫一样.
  2. 通过向控件添加WS_EX_COMPOSITED扩展窗口样式来解决闪烁问题.这种窗口样式可能会降低性能,我建议您仅在调整大小时(即需要时)添加此窗口样式.我在这里的答案中描述了如何执行此操作: TLabel和TGroupbox字幕在调整大小时闪烁.
  1. Stop using DoubleBuffered. It leads to lots of visual oddities in lots of controls. I personally avoid it like the plague.
  2. Solve your flickering problem by adding the WS_EX_COMPOSITED extended window style to your control. This window style can be a bit of a performance drag and I'd recommend that you only add this during the sizing loop, which is when you need it. I describe how to do that in my answer here: TLabel and TGroupbox Captions Flicker on Resize.

这篇关于在双缓冲TTreeView上自定义图形时闪烁的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 12:01