问题
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:
- Stop using
DoubleBuffered
. It leads to lots of visual oddities in lots of controls. I personally avoid it like the plague. - 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