Back to Devexpress

ShapeCollection.InsertTextBox(DocumentPosition) Method

officefileapi-devexpress-dot-xtrarichedit-dot-api-dot-native-dot-shapecollection-dot-inserttextbox-x28-devexpress-dot-xtrarichedit-dot-api-dot-native-dot-documentposition-x29.md

latest6.9 KB
Original Source

ShapeCollection.InsertTextBox(DocumentPosition) Method

Inserts a text box in the document.

Namespace : DevExpress.XtraRichEdit.API.Native

Assembly : DevExpress.RichEdit.v25.2.Core.dll

NuGet Package : DevExpress.RichEdit.Core

Declaration

csharp
Shape InsertTextBox(
    DocumentPosition pos
)
vb
Function InsertTextBox(
    pos As DocumentPosition
) As Shape

Parameters

NameTypeDescription
posDocumentPosition

The position of the text box’s anchor.

|

Returns

TypeDescription
Shape

The text box embedded in the document.

|

Remarks

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.

View Example

csharp
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);
vb
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

csharp
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

csharp
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

csharp
// 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

vb
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

vb
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

vb
' 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

ShapeCollection Interface

ShapeCollection Members

DevExpress.XtraRichEdit.API.Native Namespace