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
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
public T GetElement<T>(
DocumentPosition position
)
where T : RangedLayoutElement
Public Function GetElement(Of T As RangedLayoutElement)(
position As DocumentPosition
) As T
| Name | Type | Description |
|---|---|---|
| position | DocumentPosition |
A DocumentPosition object that specifies the position in the document model.
|
| Name | Description |
|---|---|
| T |
|
| Type | Description |
|---|---|
| T |
The layout element of the type designated by the specified generic type parameter.
|
The DocumentLayout object returns information about visible elements only. If the passed DocumentPosition is hidden, the GetElement method returns null.
This code snippet checks whether the first table in the document is located on the second page.
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);
}
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.
// collect information about CURRENT PAGE
RangedLayoutElement layoutPosition = currentDocumentLayout.GetElement<RangedLayoutElement>(docPosition);
if(layoutPosition != null) {
winforms-richedit-layout-api/CS/Form1.cs#L66
// 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.
' 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
' 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