Skip to main content

TcxCustomGridTableView.OnCustomDrawPartBackground Event

Enables you to custom paint a View element‘s background.

Declaration

property OnCustomDrawPartBackground: TcxGridPartCustomDrawBackgroundEvent read; write;

Remarks

This event fires for the following elements:

The OnCustomDrawPartBackground event’s Sender parameter identifies the View whose element is to be painted. The ACanvas parameter provides the drawing surface. The ADone parameter specifies whether default painting should be done after the event handler’s execution. Set this parameter to True if you have painted the element and default processing is not required.

The AViewInfo parameter provides access to the ViewInfo object whose properties and method allow you to get information about the painted element. For instance, you can determine the element to be painted and obtain the element’s bounds using this object’s Bounds property. The table below lists all the elements available for custom painting using the event and the corresponding ViewInfo object types (class names).

Element ViewInfo Class Name
Filter panel TcxGridFilterViewInfo
Find panel TcxGridFindPanelViewInfo
Footer panel TcxGridFooterViewInfo
Group footer panels TcxGridRowFooterViewInfo
Group By box TcxGridGroupByBoxViewInfo

In the example below, the Group By box is custom painted by handling the OnCustomDrawPartBackground event. The box is rendered with a custom image loaded from an external file. For other View elements, the default painting is used.

var
  APatternBrush: TBrush;  // A brush used to fill the "group by" box
procedure TForm1.FormCreate(Sender: TObject);  // Creates a pattern brush from a texture
begin
  APatternBrush := TBrush.Create;
  APatternBrush.Bitmap := TBitmap.Create;
  APatternBrush.Bitmap.LoadFromFile('c:\texture1.bmp');
end;
procedure TForm1.cxGrid1DBTableView1CustomDrawPartBackground(Sender: TcxGridTableView; ACanvas: TcxCanvas; AViewInfo: TcxCustomGridCellViewInfo; var ADone: Boolean);  // An OnCustomDrawPartBackground event handler
begin
  if AViewInfo is TcxGridGroupByBoxViewInfo then  // If the drawn UI element is a "group by" box
  begin
    ACanvas.Brush := APatternBrush;  // Assigns the loaded pattern brush to the canvas
    ACanvas.FillRect(AViewInfo.Bounds);  // Fills the "group by" box with the pattern brush
    ADone := True;  // Disables the predefined draw routine for the "group by" box
    end else
      ADone := False;  // Enables the predefined draw routines for other UI elements
  end;
end;
// Releases the pattern brush when the form is destroyed
procedure TForm1.FormDestroy(Sender: TObject);
begin
  APatternBrush.Bitmap.Free;
  APatternBrush.Free;
end;

The following screenshot shows the result of handling the event.

See Also