Flicker when custom drawing on a double buffered TTreeView

眉间皱痕 提交于 2019-12-11 03:25:37

问题


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;

... 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.

What am I missing here?


回答1:


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

  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.


来源:https://stackoverflow.com/questions/14651099/flicker-when-custom-drawing-on-a-double-buffered-ttreeview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!