[Expand]General Information
[Expand]WinForms Controls
[Expand]ASP.NET Controls and MVC Extensions
[Expand]ASP.NET Bootstrap Controls
[Expand]ASP.NET Core Bootstrap Controls
[Collapse]WPF Controls
  Prerequisites
 [Expand]What's Installed
 [Expand]Common Concepts
 [Expand]MVVM Framework
 [Collapse]Controls and Libraries
   Reporting
  [Expand]Data Grid
  [Expand]Ribbon, Bars and Menu
  [Expand]Charts Suite
  [Expand]Pivot Grid
  [Expand]Scheduler
  [Expand]Spreadsheet
  [Collapse]Rich Text Editor
   [Expand]Product Information
    Product Class Structure
    Supported Formats
   [Expand]Getting Started
   [Collapse]RichEditControl Document
    [Expand]Document Structure
    [Collapse]Document Elements
      Positions and Ranges
      Characters
      Paragraphs
      Inline Pictures
      Hyperlinks and Bookmarks
      Headers and Footers
      Tables
      Range Permissions
      Sections
      Styles
      Lists
      Shapes
      Text Boxes
      Comments
      Checkboxes
      Document Properties
   [Expand]Fields
    Text Formatting
    Import and Export
   [Expand]Page Layout
    Printing
    AutoCorrect
    Mail Merge
    Restrictions and Protection
    Syntax Highlighting
   [Expand]Visual Elements
    Services
    Events
    Commands
    HTML Tag Support
   [Expand]Examples
  [Expand]Tree List
  [Expand]Gauge Controls
  [Expand]Map Control
  [Expand]Layout Management
  [Expand]Windows Modern UI
  [Expand]Printing-Exporting
  [Expand]Data Editors
  [Expand]Navigation Controls
  [Expand]Spell Checker
  [Expand]Property Grid
  [Expand]PDF Viewer
  [Expand]TreeMap Control
  [Expand]Gantt Control
  [Expand]Diagram Control
  [Expand]Windows and Utility Controls
   Dialogs, Notifications and Panels
  [Expand]Scheduler (legacy)
 [Expand]Scaffolding Wizard
 [Expand]Localization
  Redistribution and Deployment
  Get More Help
 [Expand]API Reference
[Expand]Xamarin Controls
[Expand]Windows 10 App Controls
[Expand]Office File API
[Expand]Reporting
[Expand]Report and Dashboard Server
[Expand]Dashboard
[Expand]eXpressApp Framework
[Expand]eXpress Persistent Objects
[Expand]CodeRush
[Expand]CodeRush Classic
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation
View this topic on docs.devexpress.com (Learn more)

Text Boxes

The following topic describes how to insert and modify text boxes in the RichEditControl.

Expanded Manage Text Boxes in Code

Create a Text Box

To create a text box anchored to the given document position, use the ShapeCollection.InsertTextBox method as shown below.

By default, the inserted text box is positioned at the beginning of the first paragraph on the page that contains a floating object's anchor.

Note

A complete sample project is available at https://github.com/DevExpress-Examples/text-boxes-simple-example-t481625.

Select the Text Box in the Document

Both floating pictures and text boxes are stored in the document's ShapeCollection. To determine the type of the retrieved collection item, check its Shape.TextBox property. If the property value is null, the target item is a floating picture; otherwise, it is a text box.

The code snippet below uses the Shape.TextBox property to distinguish text boxes from floating pictures and rotate them.

The following code rotates text boxes and resizes floating pictures.

Insert and Modify Text in the Text Box

To access the text box contents, use the TextBox.Document property. The following methods allow you to insert different document elements to the text box.

Member Description
SubDocument.BeginUpdate Opens the given SubDocument instance for modification.
SubDocument.InsertText Inserts a text string to the specified position.
TableCollection.Create Inserts a table to the specified position within the document.
ShapeCollection.InsertPicture Inserts a floating picture to the given document position.
DocumentImageCollection.Insert Inserts an inline image to the specified position.
ShapeCollection.InsertTextBox Inserts a text box to the specified position.
SubDocument.EndUpdate Finalizes the document update.

The text box content can be formatted as a regular text. For details, refer to the Text Formatting topic.

The code example below inserts a text string to the text box and applies formatting to the inserted content.

Note

A complete sample project is available at https://github.com/DevExpress-Examples/text-boxes-simple-example-t481625.

Change the Text Box Style

Use the API from the table below to change the text box appearance.

Member Description
ShapeFill.Color Sets the text box' background color.
ShapeLine.Color Sets the text box' border line color.
ShapeLine.Thickness Sets the text box' border line thickness.

The code snippet below changes the text box' color options so it appears as on the following image.

Note

A complete sample project is available at https://github.com/DevExpress-Examples/text-boxes-simple-example-t481625.

Rotate and Resize the Text Box

To resize the text box, use one of the members from the table.

Member Description
Shape.ZOrder Changes the shape position in the Z-order. Use this property to place the text box behind or in front of other document shapes.
Shape.Offset Positions the text box relative to a certain point within the document layout.
Shape.ScaleX Scales the text box width to a given value.
Shape.ScaleY Scales the text box height to a given value.
Shape.RelativeHorizontalPosition Specifies the horizontal alignment of the text box relative to the specific page element.
Shape.RelativeVerticalPosition Specifies the vertical alignment of the text box relative to the specific page element.
Shape.RotationAngle Rotates the text box at a given angle.

The following code snippet resizes the text box so it appears as on the image below.

Note

A complete sample project is available at https://github.com/DevExpress-Examples/text-boxes-simple-example-t481625.

Expanded Text Boxes in the UI

End-users can insert the text box to any position within the document using the Insert Ribbon tab. To learn how to provide the application with the ribbon menu, refer to the How to: Create a Simple Word Processor with a Ribbon UI topic.

When the text box is selected, the Picture Tools | Format tab is activated. This tab allows end-users to position the text box within the document and set the shape's fill or border color. The text box content can be formatted using the Home ribbon tab.

By default, the text box height is automatically increased to display the contained text. End-users can rotate and resize the text box using specially designed handles as shown on the following image. When the text box rotates, its content is also rotated.

To set more advanced options, use the Floating Object Layout Dialog, which can be invoked from the context menu.

Tip

Inserting text boxes to the document can be forbidden. To do that, use the DocumentCapabilitiesOptions.FloatingObjects property.

Is this topic helpful?​​​​​​​