Skip to main content

TcxCustomTreeView.OnCustomDraw Event

Allows you to custom pain a tree view control.

Declaration

property OnCustomDraw: TTVCustomDrawEvent read; write;

Remarks

The OnCustomDraw event occurs each time the control needs to be repainted, but before the default painting is made. The Sender parameter specifies the control that is painted. Use the Canvas property of the object representing it to obtain the canvas used to paint. The ARect parameter returns the bounding rectangle of the control so that you know where to paint.

The DefaultDraw parameter of the event specifies whether further painting must be performed by the control. Set this parameter to False if all desired painting is performed within the OnCustomDraw event handler. In this instance, the control will not paint nodes. The OnCustomDrawItem and OnAdvancedCustomDrawItem events will not be raised either. If you only need to custom paint the control’s background, set the DefaultDraw parameter to True.

Note that you can also custom paint the control’s foreground. Please refer to the OnAdvancedCustomDraw event description for details on how to achieve this.

The following sample code handles the OnCustomDraw event to fill the background of the tree view with a texture. The DefaultDraw parameter is not set to False to allow node painting.

procedure TForm1.cxTreeView1CustomDraw(Sender: TCustomTreeView;
  const ARect: TRect; var DefaultDraw: Boolean);
var
  TextureBrush: HBRUSH;
  Bitmap: TBitmap;
begin
  Bitmap := TBitmap.Create;
  Bitmap.LoadFromFile('c:\texture.bmp');
  TextureBrush := CreatePatternBrush(Bitmap.Handle);
  FillRect(Sender.Canvas.Handle, ARect, TextureBrush);
  SetBkMode(Sender.Canvas.Handle, TRANSPARENT);
end;

Here is the result of code execution.

See Also