Back to Devexpress

TextBox.Document Property

officefileapi-devexpress-dot-xtrarichedit-dot-api-dot-native-dot-textbox.md

latest8.0 KB
Original Source

TextBox.Document Property

Provides access to text box content.

Namespace : DevExpress.XtraRichEdit.API.Native

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

NuGet Package : DevExpress.RichEdit.Core

Declaration

csharp
SubDocument Document { get; }
vb
ReadOnly Property Document As SubDocument

Property Value

TypeDescription
SubDocument

An object that exposes text box content.

|

Remarks

The example below inserts a paragraph and a picture from the main document into a text box. Use the TextBox.Document property to access and modify text box content.

View Example

csharp
Document document = server.Document;
document.LoadDocument("Documents\\Grimm.docx", DocumentFormat.Docx);
// Access a text box in the document.
Shape myTextBox = document.Shapes[0];
// Specify that the text box should resize to fit its content.
myTextBox.ShapeFormat.TextBox.ResizeShapeToFitText = true;
// Access text box content.
SubDocument boxedDocument = myTextBox.ShapeFormat.TextBox.Document;
int appendPosition = myTextBox.ShapeFormat.TextBox.Document.Range.End.ToInt();
// Append the second paragraph of the main document to the text box.
DocumentRange newRange = boxedDocument.AppendDocumentContent(document.Paragraphs[1].Range);
boxedDocument.Paragraphs.Insert(newRange.Start);
// Insert an image form the main document into the text box.
boxedDocument.Images.Insert(boxedDocument.CreatePosition(appendPosition), document.Images[0].Image.NativeImage);
// Resize the image so that its size equals the image in the main document.
boxedDocument.Images[0].Size = document.Images[0].Size;
vb
Dim document As Document = server.Document
document.LoadDocument("Documents\Grimm.docx", DocumentFormat.Docx)
' Access a text box in the document.
Dim myTextBox As Shape = document.Shapes(0)
' Specify that the text box should resize to fit its content.
myTextBox.ShapeFormat.TextBox.ResizeShapeToFitText = True
' Access text box content.
Dim boxedDocument As SubDocument = myTextBox.ShapeFormat.TextBox.Document
Dim appendPosition As Integer = myTextBox.ShapeFormat.TextBox.Document.Range.End.ToInt()
' Append the second paragraph of the main document to the text box.
Dim newRange As DocumentRange = boxedDocument.AppendDocumentContent(document.Paragraphs(1).Range)
boxedDocument.Paragraphs.Insert(newRange.Start)
' Insert an image form the main document into the text box.
boxedDocument.Images.Insert(boxedDocument.CreatePosition(appendPosition), document.Images(0).Image.NativeImage)
' Resize the image so that its size equals the image in the main document.
boxedDocument.Images(0).Size = document.Images(0).Size

The following code snippets (auto-collected from DevExpress Examples) contain references to the Document property.

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#L62

csharp
// Modify text box content.
SubDocument textBoxDocument = myTextBox.ShapeFormat.TextBox.Document;
textBoxDocument.AppendText("TextBox Text");

wpf-richedit-document-api/CS/DXRichEditControlAPISample/CodeExamples/ShapesActions.cs#L73

csharp
// Modify text box content.
SubDocument textBoxDocument = myTextBox.ShapeFormat.TextBox.Document;
textBoxDocument.AppendText("TextBox Text");

word-document-api-examples/CS/CodeExamples/ShapesActions.cs#L119

csharp
// Modify text box content.
SubDocument textBoxDocument = myTextBox.ShapeFormat.TextBox.Document;
textBoxDocument.AppendText("TextBox Text");

winforms-richedit-iterate-through-all-sub-documents/CS/SubDocumentHelper.cs#L46

csharp
if (shape.ShapeFormat.TextBox != null)
            subDocumentProcessor(shape.ShapeFormat.TextBox.Document);
}

word-document-api-iterate-through-all-sub-documents/CS/SubDocumentHelper.cs#L46

csharp
if (shape.ShapeFormat.TextBox != null)
            subDocumentProcessor(shape.ShapeFormat.TextBox.Document);
}

winforms-richedit-document-api/VB/RichEditAPISample/CodeExamples/Shapes.vb#L57

vb
' Modify text box content.
Dim textBoxDocument As DevExpress.XtraRichEdit.API.Native.SubDocument = myTextBox.ShapeFormat.TextBox.Document
textBoxDocument.AppendText("TextBox Text")

wpf-richedit-document-api/VB/DXRichEditControlAPISample/CodeExamples/ShapesActions.vb#L64

vb
' Modify text box content.
Dim textBoxDocument As SubDocument = myTextBox.ShapeFormat.TextBox.Document
textBoxDocument.AppendText("TextBox Text")

word-document-api-examples/VB/CodeExamples/ShapesActions.vb#L97

vb
' Modify text box content.
Dim textBoxDocument As DevExpress.XtraRichEdit.API.Native.SubDocument = myTextBox.ShapeFormat.TextBox.Document
textBoxDocument.AppendText("TextBox Text")

winforms-richedit-iterate-through-all-sub-documents/VB/SubDocumentHelper.vb#L40

vb
For Each shape As Shape In shapes
    If shape.ShapeFormat.TextBox IsNot Nothing Then subDocumentProcessor(shape.ShapeFormat.TextBox.Document)
Next

word-document-api-iterate-through-all-sub-documents/VB/SubDocumentHelper.vb#L40

vb
For Each shape As Shape In shapes
    If shape.ShapeFormat.TextBox IsNot Nothing Then subDocumentProcessor(shape.ShapeFormat.TextBox.Document)
Next

See Also

TextBox Interface

TextBox Members

DevExpress.XtraRichEdit.API.Native Namespace