Skip to main content

DevExpress v24.2 Update — Your Feedback Matters

Our What's New in v24.2 webpage includes product-specific surveys. Your response to our survey questions will help us measure product satisfaction for features released in this major update and help us refine our plans for our next major release.

Take the survey Not interested

How to Insert a Floating Text Box

  • 3 minutes to read

This topic explains how to create a floating text box and customize its settings programmatically. A text box is a fully functional subdocument hosted within a floating shape.

You can manage, position and customize text floating boxes within a rich text document via the Rich Edit control’s public API that provides the InsertTextBox function, available both at the document and subdocument levels. The function creates and anchors an empty floating text box to the beginning of the page that includes the specified document position.

Refer to the following code example:

uses
..., dxCoreGraphics, cxGeometry;  // Add these units to the uses clause...
//...
var
  ADocument: IdxRichEditDocument;
  ATextBoxShape: IdxRichEditShape;
  ATextBoxSubDocument: IdxRichEditSubDocument;
begin
  ADocument := dxRichEditControl1.Document;
  ADocument.&Unit := TdxRichEditDocumentUnit.Point;  // Sets the measurement unit used to specify positions and sizes within the document
  ATextBoxShape := ADocument.InsertTextBox(ADocument.CreatePosition(0));  // Creates a new empty text box
  ATextBoxSubDocument := ATextBoxShape.TextBox.Document;
// Adds text to the text box
  ATextBoxSubDocument.AppendText('Lorem ipsum dolor sit amet, eu cum consul ignota. ');
  ATextBoxSubDocument.AppendText('Ea purto ubique voluptua nam, ea malorum definebas assueverit mel. ');
  ATextBoxSubDocument.AppendText('Qui ea alia mutat petentium ius latine oblique conclusionemque ne.');
  ATextBoxShape.TextWrapping := TdxRichEditTextWrappingType.Square;  // Anchors the floating text box to the document's text layer and wraps text around all sides of the floating box's bounding rectangle
  ATextBoxShape.HorizontalAlignment := TdxRichEditShapeHorizontalAlignment.Center;
  ATextBoxShape.Offset := TdxPointF.Create(0, 200);
  ATextBoxShape.RotationAngle := 45;
// Sets the floating shape's appearance settings
  ATextBoxShape.Line.Thickness := 1;
  ATextBoxShape.Line.Color := TdxAlphaColors.Black;
  ATextBoxShape.Fill.Color := TdxAlphaColors.Bisque;
// Sets the margins between the text box's bounding rectangle and the parent document's text
  ATextBoxShape.MarginBottom := 10;
  ATextBoxShape.MarginLeft := 10;
  ATextBoxShape.MarginRight := 10;
  ATextBoxShape.MarginTop := 10;
end;

Alternatively, you can insert text boxes by calling the document’s Shapes.InsertTextBox function.