Skip to main content

TcxCustomListView.OnCustomDraw Event

Enables you to paint the list view control in a custom manner.

Declaration

property OnCustomDraw: TLVCustomDrawEvent 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 which 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 the desired painting is performed within the OnCustomDraw event handler. In this case, the control will not paint items. The OnCustomDrawItem and OnAdvancedCustomDrawItem events will not be raised also. However, if you need to perform custom painting of the control’s background only, set the DefaultDraw parameter to True.

Note that you can also perform painting of the control’s foreground. Please refer to the OnAdvancedCustomDraw event description for details on performing this.

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

procedure TForm1.cxListView1CustomDraw(Sender: TCustomListView;
  const ARect: TRect; var DefaultDraw: Boolean);
var
  ABitmap: TBitmap;
  ABrush: HBRUSH;
begin
  ABitmap := TBitmap.Create;
  ABitmap.LoadFromFile('C:\IMAGES\lightblue.BMP');
  ABrush := CreatePatternBrush(ABitmap.Handle);
  FillRect(Sender.Canvas.Handle, ARect, ABrush);
  SetBkMode(Sender.Canvas.Handle, TRANSPARENT);
  ABitmap.Free;
end;

The following image demonstrates the result of the code execution:

See Also