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-sizef-x29.md
Inserts a text box of the specified size in the document.
Namespace : DevExpress.XtraRichEdit.API.Native
Assembly : DevExpress.RichEdit.v25.2.Core.dll
NuGet Package : DevExpress.RichEdit.Core
Shape InsertTextBox(
DocumentPosition pos,
SizeF size
)
Function InsertTextBox(
pos As DocumentPosition,
size As SizeF
) As Shape
| Name | Type | Description |
|---|---|---|
| pos | DocumentPosition |
The position of the text box’s anchor.
| | size | SizeF |
An object that specifies the text box’s width and height. The Document.Unit property defines the measurement units.
|
| Type | Description |
|---|---|
| Shape |
The text box embedded in the document.
|
The InsertTextBox method adds a text box to the page that contains the text box’s anchor and sets its position as follows:
the absolute horizontal position to the right of the column is 0;
the absolute vertical position below the paragraph is 0.
Use the Shape.ShapeFormat.TextBox.Document property to access and modify text box content.
The example below creates a text box and centers it horizontally on the page.
Document document = wordProcessor.Document;
document.AppendText("Line One\nLine Two\nLine Three");
Shape myTextBox = document.Shapes.InsertTextBox(document.CreatePosition(15), new SizeF(400, 200));
myTextBox.HorizontalAlignment = ShapeHorizontalAlignment.Center;
// Fill the text box with a 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.AppendText("Line One" & vbLf & "Line Two" & vbLf & "Line Three")
Dim myTextBox As Shape = document.Shapes.InsertTextBox(document.CreatePosition(15), New SizeF(400, 200))
myTextBox.HorizontalAlignment = ShapeHorizontalAlignment.Center
' Fill the text box with a 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