officefileapi-devexpress-dot-xtrarichedit-dot-api-dot-native-dot-shapecollection-dot-inserttextbox-x28-devexpress-dot-xtrarichedit-dot-api-dot-native-dot-documentposition-x29.md
Inserts a text box in the document.
Namespace : DevExpress.XtraRichEdit.API.Native
Assembly : DevExpress.RichEdit.v25.2.Core.dll
NuGet Package : DevExpress.RichEdit.Core
Shape InsertTextBox(
DocumentPosition pos
)
Function InsertTextBox(
pos As DocumentPosition
) As Shape
| Name | Type | Description |
|---|---|---|
| pos | DocumentPosition |
The position of the text box’s anchor.
|
| Type | Description |
|---|---|
| Shape |
The text box embedded in the document.
|
The InsertTextBox method places a text box at the beginning of the page that contains the text box’s anchor. Use the Shape.ShapeFormat.TextBox.Document property to access and modify text box content.
Document document = wordProcessor.Document;
document.AppendText("Line One\nLine Two\nLine Three");
Shape myTextBox = document.Shapes.InsertTextBox(document.CreatePosition(15));
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))
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)
The following code snippets (auto-collected from DevExpress Examples) contain references to the InsertTextBox(DocumentPosition) method.
Note
The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.
winforms-richedit-document-api/CS/RichEditAPISample/CodeExamples/Shapes.cs#L54
document.AppendText("Line One\nLine Two\nLine Three");
Shape myTextBox = document.Shapes.InsertTextBox(document.CreatePosition(15));
myTextBox.HorizontalAlignment = ShapeHorizontalAlignment.Center;
wpf-richedit-document-api/CS/DXRichEditControlAPISample/CodeExamples/ShapesActions.cs#L65
document.AppendText("Line One\nLine Two\nLine Three");
Shape myTextBox = document.Shapes.InsertTextBox(document.CreatePosition(15));
myTextBox.HorizontalAlignment = ShapeHorizontalAlignment.Center;
word-document-api-examples/CS/CodeExamples/ShapesActions.cs#L106
// Insert a text box at the specified position.
Shape myTextBox = document.Shapes.InsertTextBox(document.CreatePosition(15));
winforms-richedit-document-api/VB/RichEditAPISample/CodeExamples/Shapes.vb#L49
document.AppendText("Line One" & Global.Microsoft.VisualBasic.Constants.vbLf & "Line Two" & Global.Microsoft.VisualBasic.Constants.vbLf & "Line Three")
Dim myTextBox As DevExpress.XtraRichEdit.API.Native.Shape = document.Shapes.InsertTextBox(document.CreatePosition(15))
myTextBox.HorizontalAlignment = DevExpress.XtraRichEdit.API.Native.ShapeHorizontalAlignment.Center
wpf-richedit-document-api/VB/DXRichEditControlAPISample/CodeExamples/ShapesActions.vb#L56
document.AppendText("Line One" & vbLf & "Line Two" & vbLf & "Line Three")
Dim myTextBox As Shape = document.Shapes.InsertTextBox(document.CreatePosition(15))
myTextBox.HorizontalAlignment = ShapeHorizontalAlignment.Center
word-document-api-examples/VB/CodeExamples/ShapesActions.vb#L88
' Insert a text box at the specified position.
Dim myTextBox As DevExpress.XtraRichEdit.API.Native.Shape = document.Shapes.InsertTextBox(document.CreatePosition(15))
' Align the text box horizontally.
See Also