Skip to main content
Pie
ra0

TcxCanvas.DrawTexT(string,TRect,TAlignment,TcxAlignmentVert,Boolean,Boolean) Method

Draws formatted text within a specified rectangle on the canvas.

Declaration

procedure DrawTexT(const Text: string; R: TRect; AAlignmentHorz: TAlignment; AAlignmentVert: TcxAlignmentVert; AMultiLine: Boolean; AShowEndEllipsis: Boolean); overload;

Parameters

Name Type Description
Text string

A text string to display.

R TRect

The target rectangle on the canvas.

AAlignmentHorz TAlignment

Enumerates available horizontal text alignment options.

AAlignmentVert TcxAlignmentVert

Enumerates available vertical text alignment options.

AMultiLine Boolean

Specifies if the procedure can split up displayed text into multiple lines.

AShowEndEllipsis Boolean

Specifies if the procedure shows an ellipsis at the end of the displayed text string if it does not fit into the target rectangle.

Remarks

Call this procedure and pass a text string as the Text parameter to draw the string within a rectangle passed as the R parameter. The DrawTexT procedure uses the background color and font settings of the canvas to draw text.

Use the AAlignmentHorz and AAlignmentVert parameters to position text within the target rectangle. Pass True as the AMultiLine parameter to break down text into multiple lines if it does not fit into the target rectangle width. Additionally, you can pass True as the AShowEndEllipsis parameter to crop the last portion of text that does not fit into the target rectangle, and display an ellipsis at the end.

The following code is a TcxCustomGridTableView.OnCustomDrawPartBackground event handler that wraps a caption into multiple lines and shows an ellipsis at the end if the caption does not fit into the “Group By” box.

procedure TViewTableSimpleDemoMainForm.cxgFilmsDBTableViewCustomDrawPartBackground(
  Sender: TcxCustomGridTableView; ACanvas: TcxCanvas;
  AViewInfo: TcxCustomGridCellViewInfo; var ADone: Boolean);
var
  FBounds: TRect;
begin
  FBounds := AViewInfo.Bounds;
  ACanvas.FillRect(FBounds);
  InflateRect(FBounds, -150, -4);
  OffsetRect(FBounds, 140, 0);
  ACanvas.DrawText('This is the Group By box. ' +
                   'It is used to group records by field values. ' +
                   'Drag a column header here to group by that field.',
                   FBounds, cxWordBreak or cxShowEndEllipsis);
  ADone := True;
end;

See Also