Back to Devexpress

DocumentLayout.GetElement<T>(DocumentPosition) Method

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

latest6.4 KB
Original Source

DocumentLayout.GetElement<T>(DocumentPosition) Method

Returns the layout element of the type designated by the specified generic type parameter 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 T GetElement<T>(
    DocumentPosition position
)
    where T : RangedLayoutElement
vb
Public Function GetElement(Of T As RangedLayoutElement)(
    position As DocumentPosition
) As T

Parameters

NameTypeDescription
positionDocumentPosition

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

|

Type Parameters

NameDescription
T

|

Returns

TypeDescription
T

The layout element of the type designated by the specified generic type parameter.

|

Remarks

The DocumentLayout object returns information about visible elements only. If the passed DocumentPosition is hidden, the GetElement method returns null.

Example

This code snippet checks whether the first table in the document is located on the second page.

View Example

csharp
DevExpress.XtraRichEdit.API.Native.Table table = richEditControl1.Document.Tables.First;
if (table != null)
{
    // Obtain the layout element related to the table.
    LayoutTable ltable = richEditControl1.DocumentLayout.GetElement<LayoutTable>(table.Range.Start);
    // Obtain zero-based page index of the page containing the layout element.
    int pageIndex = this.richEditControl1.DocumentLayout.GetPageIndex(ltable);
    // Check whether the layout element is located at the second page.
    string s = "Layout verified.";
    if (pageIndex != 1)
        s = "The first table is not on the page 2. Review pagination.";
    MessageBox.Show(s, "Check Layout", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
vb
Dim table As DevExpress.XtraRichEdit.API.Native.Table = richEditControl1.Document.Tables.First
If table IsNot Nothing Then
    ' Obtain the layout element related to the table.
    Dim ltable As LayoutTable = richEditControl1.DocumentLayout.GetElement(Of LayoutTable)(table.Range.Start)
    ' Obtain zero-based page index of the page containing the layout element.
    Dim pageIndex As Integer = Me.richEditControl1.DocumentLayout.GetPageIndex(ltable)
    ' Check whether the layout element is located at the second page.
    Dim s As String = "Layout verified."
    If pageIndex <> 1 Then
        s = "The first table is not on the page 2. Review pagination."
    End If
    MessageBox.Show(s, "Check Layout", MessageBoxButtons.OK, MessageBoxIcon.Information)
End If

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

csharp
// collect information about CURRENT PAGE
RangedLayoutElement layoutPosition = currentDocumentLayout.GetElement<RangedLayoutElement>(docPosition);
if(layoutPosition != null) {

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

csharp
// Obtain the layout element related to the table.
LayoutTable ltable = richEditControl1.DocumentLayout.GetElement<LayoutTable>(table.Range.Start);
// Obtain zero-based page index of the page containing the layout element.

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

vb
' collect information about CURRENT PAGE
Dim layoutPosition As RangedLayoutElement = currentDocumentLayout.GetElement(Of RangedLayoutElement)(docPosition)
If layoutPosition IsNot Nothing Then

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

vb
' Obtain the layout element related to the table.
Dim ltable As LayoutTable = richEditControl1.DocumentLayout.GetElement(Of LayoutTable)(table.Range.Start)
' Obtain zero-based page index of the page containing the layout element.

See Also

DocumentLayout Class

DocumentLayout Members

DevExpress.XtraRichEdit.API.Layout Namespace