Back to Devexpress

DocumentLayout.GetElement(DocumentPosition, LayoutType) Method

officefileapi-devexpress-dot-xtrarichedit-dot-api-dot-layout-dot-documentlayout-dot-getelement-x28-devexpress-dot-xtrarichedit-dot-api-dot-native-dot-documentposition-devexpress-dot-xtrarichedit-dot-api-dot-layout-dot-layouttype-x29.md

latest6.0 KB
Original Source

DocumentLayout.GetElement(DocumentPosition, LayoutType) Method

Gets the layout element of the specified type which relates to the specified position in the document model.

Namespace : DevExpress.XtraRichEdit.API.Layout

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

NuGet Package : DevExpress.RichEdit.Core

Declaration

csharp
public RangedLayoutElement GetElement(
    DocumentPosition position,
    LayoutType type
)
vb
Public Function GetElement(
    position As DocumentPosition,
    type As LayoutType
) As RangedLayoutElement

Parameters

NameTypeDescription
positionDocumentPosition

A DocumentPosition object that specifies the position in the document model.

| | type | LayoutType |

A LayoutType enumeration that specifies the type of the requested layout element.

|

Returns

TypeDescription
RangedLayoutElement

A RangedLayoutElement class descendant if the specified layout type can be related to a document position; otherwise, an exception is thrown.

|

Remarks

Important

If the specified layout type cannot be related to a document position (e.g. LayoutType.BookmarkStartBox, LayoutType.BookmarkEndBox), an exception is thrown.

The following code snippets (auto-collected from DevExpress Examples) contain references to the GetElement(DocumentPosition, LayoutType) 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-layout-api-practical-usage/CS/WindowsFormsApplication1/DocumentLayoutHelper/RichEditDocumentLayoutAnalyzer.cs#L41

csharp
RangedLayoutElement tableCell = currentDocumentLayout.GetElement(docPosition, LayoutType.TableCell);
if(tableCell != null)

winforms-richedit-layout-api/CS/Form1.cs#L83

csharp
DocumentPosition pos = subDoc.CreatePosition(richEditControl1.Document.CaretPosition.ToInt() == 0 ? 0 : richEditControl1.Document.CaretPosition.ToInt() - 1);
LayoutPageArea pageArea = richEditControl1.DocumentLayout.GetElement(pos, LayoutType.PageArea) as LayoutPageArea;
LayoutPage page = pageArea.GetParentByType<LayoutPage>();

word-document-api-use-layout-api-to-manage-document-pages/CS/Program.cs#L50

csharp
var documentLayout = rtfProcessor.DocumentLayout;
var row = documentLayout.GetElement(pos, LayoutType.Row);
LayoutPage page = row.GetParentByType<LayoutPage>();

winforms-richedit-layout-api-practical-usage/VB/WindowsFormsApplication1/DocumentLayoutHelper/RichEditDocumentLayoutAnalyzer.vb#L46

vb
Dim tableCell As RangedLayoutElement = currentDocumentLayout.GetElement(docPosition, LayoutType.TableCell)
If tableCell IsNot Nothing Then

winforms-richedit-layout-api/VB/Form1.vb#L70

vb
Dim pos As DocumentPosition = subDoc.CreatePosition(If(richEditControl1.Document.CaretPosition.ToInt() = 0, 0, richEditControl1.Document.CaretPosition.ToInt() - 1))
Dim pageArea As LayoutPageArea = TryCast(richEditControl1.DocumentLayout.GetElement(pos, LayoutType.PageArea), LayoutPageArea)
Dim page As LayoutPage = pageArea.GetParentByType(Of LayoutPage)()

word-document-api-use-layout-api-to-manage-document-pages/VB/Program.vb#L38

vb
Dim documentLayout = rtfProcessor.DocumentLayout
Dim row = documentLayout.GetElement(pos, LayoutType.Row)
Dim page As LayoutPage = row.GetParentByType(Of LayoutPage)()

See Also

DocumentLayout Class

DocumentLayout Members

DevExpress.XtraRichEdit.API.Layout Namespace