Log In
Home
Support
Demos
Documentation
Blogs
Training
Webinars
[Expand]General Information
[Collapse]WinForms Controls
  Prerequisites
 [Expand]What's Installed
 [Expand]Build an Application
 [Collapse]Controls and Libraries
  [Expand]Forms and User Controls
  [Expand]Messages, Notifications and Dialogs
  [Expand]Editors and Simple Controls
  [Expand]Ribbon, Bars and Menu
  [Expand]Application UI Manager
  [Expand]Docking Library
  [Expand]Data Grid
  [Expand]Vertical Grid
  [Expand]Pivot Grid
  [Expand]Tree List
  [Expand]Chart Control
  [Expand]Diagrams
  [Expand]Gauges
  [Expand]Map Control
  [Expand]Scheduler
  [Expand]Spreadsheet
  [Collapse]Rich Text Editor
   [Expand]Product Information
    Product Class Structure
   [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
      Numbered and Bulleted Lists
      Floating Objects (Shapes)
      Text Boxes
      Comments
      Document Properties
   [Expand]Fields
    Text Formatting
    Import and Export
   [Expand]Page Layout
    Printing
    Spell Checking
    AutoCorrect
    Mail Merge
    Restrictions and Protection
    Syntax Highlighting
    Traversing the Document
   [Expand]Visual Elements
    Services
    Events
    Commands
   [Expand]Member Tables
    Keyboard Shortcuts
    HTML Tag Interpretation
   [Expand]Examples
  [Expand]Spell Checker
  [Expand]Form Layout Managers
  [Expand]Navigation Controls
  [Expand]Printing-Exporting
  [Expand]PDF Viewer
   Reporting
  [Expand]Snap
  [Expand]TreeMap Control
 [Expand]Common Features
  Get More Help
 [Expand]API Reference
[Expand]ASP.NET Controls and MVC Extensions
[Expand]ASP.NET Bootstrap Controls
[Expand]ASP.NET Core Bootstrap Controls
[Expand]WPF Controls
[Expand]Xamarin Controls
[Expand]Windows 10 App Controls
[Expand]Document Server
[Expand]Reporting
[Expand]Report Server
[Expand]Dashboard
[Expand]eXpressApp Framework
[Expand]CodeRush
[Expand]CodeRush Classic
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation

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.


Show Me

A complete sample project is available in the DevExpress Code Examples database at http://www.devexpress.com/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.

Show Me

A complete sample project is available in the DevExpress Code Examples database at http://www.devexpress.com/example=E5219.

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.

Show Me

A complete sample project is available in the DevExpress Code Examples database at http://www.devexpress.com/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.

Show Me

A complete sample project is available in the DevExpress Code Examples database at http://www.devexpress.com/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.

Show Me

A complete sample project is available in the DevExpress Code Examples database at http://www.devexpress.com/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 Inline and 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.

Expanded See Also

How would you rate this topic?​​​​​​​