TcxCustomTreeView.OnAdvancedCustomDraw Event
Enables you to paint the tree view control (or a part of it) before or after default painting takes place.
#Declaration
property OnAdvancedCustomDraw: TTVAdvancedCustomDrawEvent read; write;
#Remarks
The OnAdvancedCustomDraw event fires at different stages of control painting. First, it fires before any default painting is performed. Then it fires after all painting is finished. Use the Stage parameter to determine the stage of painting. It returns cdPrePaint if the event fires before any other painting. If the cdPostPaint value is returned, all painting procedures have already been finished. Note that the Stage parameter cannot return any other value listed by the TCustomDrawState enumeration.
The DefaultDraw parameter specifies whether default painting must proceed after the OnAdvancedCustomDraw event is executed. If handling the event when the Stage parameter is cdPrePaint, setting the DefaultDraw parameter to True prohibits all further painting. This means that control items will not be painted. You cannot paint them manually either, since the OnCustomDrawItem and OnAdvancedCustomDrawItem events will not fire. Thus, you need to set the DefaultDraw parameter to True only when all the desired painting is performed in the OnAdvancedCustomDraw event and no further painting is needed.
When the Stage parameter returns cdPostPaint, the DefaultDraw parameter should not be used. No painting will take place.
Note
Handle the On
The Sender parameter of the event provides access to the underlying tree view control. Use the Canvas property of the object representing this parameter to obtain the canvas used to paint. The bounding rectangle of the control can be obtained using the ARect parameter.
The following sample code shows how to perform painting when all default painting routines are finished. The code handles the OnAdvancedCustomDraw event to paint a red X over the control’s client area.
procedure TForm1.cxTreeView1AdvancedCustomDraw(Sender: TCustomTreeView;
const ARect: TRect; Stage: TCustomDrawStage; var DefaultDraw: Boolean);
begin
if Stage = cdPostPaint then
begin
with Sender.Canvas do
begin
Pen.Color := clRed;
Pen.Style := psSolid;
Pen.Width := 3;
MoveTo(ARect.Left, ARect.Top);
LineTo(ARect.Right, ARect.Bottom);
MoveTo(ARect.Left, ARect.Bottom);
LineTo(ARect.Right, ARect.Top);
end;
end
end;
The result of code execution is as follows:
Important
Use the On