officefileapi-devexpress-dot-xtrarichedit-dot-api-dot-native-dot-shapecollection-dot-inserttextbox-x28-devexpress-dot-xtrarichedit-dot-api-dot-native-dot-documentposition-system-dot-drawing-dot-rectanglef-x29.md
Inserts a text box at the specified position in the document.
Namespace : DevExpress.XtraRichEdit.API.Native
Assembly : DevExpress.RichEdit.v25.2.Core.dll
NuGet Package : DevExpress.RichEdit.Core
Shape InsertTextBox(
DocumentPosition pos,
RectangleF bounds
)
Function InsertTextBox(
pos As DocumentPosition,
bounds As RectangleF
) As Shape
| Name | Type | Description |
|---|---|---|
| pos | DocumentPosition |
The position of the text box’s anchor.
| | bounds | RectangleF |
An object that specifies the text box’s size and location (relative to the top and left edges of the page). The Document.Unit property defines the measurement units.
|
| Type | Description |
|---|---|
| Shape |
The text box embedded in the document.
|
Use the Shape.ShapeFormat.TextBox.Document property to access and modify text box content.
The example below creates a text box and places it on the page as follows:
the absolute horizontal position is 1.5 inches to the right of the page;
the absolute vertical position is one inch below the page.
Document document = wordProcessor.Document;
document.Unit = DevExpress.Office.DocumentUnit.Inch;
// Create a text box.
Shape myTextBox = document.Shapes.InsertTextBox(document.Range.Start, new RectangleF(1.5f, 1f, 1.5f, 0.5f));
// Specify the text box background color.
myTextBox.Fill.Color = System.Drawing.Color.WhiteSmoke;
// Draw a border around the text box.
myTextBox.Line.Color = System.Drawing.Color.Black;
myTextBox.Line.Thickness = 1;
// Modify text box content.
SubDocument textBoxDocument = myTextBox.ShapeFormat.TextBox.Document;
textBoxDocument.AppendText("Text box");
CharacterProperties cp = textBoxDocument.BeginUpdateCharacters(textBoxDocument.Range.Start, 4);
cp.ForeColor = System.Drawing.Color.Orange;
cp.FontSize = 24;
textBoxDocument.EndUpdateCharacters(cp);
Dim document As Document = wordProcessor.Document
document.Unit = DevExpress.Office.DocumentUnit.Inch
' Create a text box.
Dim myTextBox As Shape = document.Shapes.InsertTextBox(document.Range.Start, New RectangleF(1.5F, 1F, 1.5F, 0.5F))
' Specify the text box background color.
myTextBox.Fill.Color = System.Drawing.Color.WhiteSmoke
' Draw a border around the text box.
myTextBox.Line.Color = System.Drawing.Color.Black
myTextBox.Line.Thickness = 1
' Modify text box content.
Dim textBoxDocument As SubDocument = myTextBox.ShapeFormat.TextBox.Document
textBoxDocument.AppendText("Text box")
Dim cp As CharacterProperties = textBoxDocument.BeginUpdateCharacters(textBoxDocument.Range.Start, 4)
cp.ForeColor = System.Drawing.Color.Orange
cp.FontSize = 24
textBoxDocument.EndUpdateCharacters(cp)
See Also