Skip to main content
A newer version of this page is available. .

RichEditControl.GetPositionFromPoint(PointF) Method

Gets the position in the document closest to the specified point.

Namespace: DevExpress.Xpf.RichEdit

Assembly: DevExpress.Xpf.RichEdit.v19.1.dll

Declaration

public DocumentPosition GetPositionFromPoint(
    PointF clientPoint
)

Parameters

Name Type Description
clientPoint PointF

A PointF structure specifying the location for which the position is retrieved. The point coordinates are measured in documents units.

Returns

Type Description
DocumentPosition

A DocumentPosition object representing a position in the document.

Remarks

The GetPositionFromPoint method returns the closest document position for a specified point or null reference (Nothingin Visual Basic). The coordinate system used is a standard one, where the origin is located at the upper left corner of the RichEditControl. Use the Units.PixelsToDocuments method to translate coordinates.

This code snippet illustrates handling the MouseMove event of the RichEditControl and using the RichEditControl.GetPositionFromPoint method to obtain the corresponding position in the document. If the position under the mouse cursor belongs to a bookmark, this bookmark is selected using the SubDocument.SelectBookmark method, and its name and text fragment are displayed in the text box below.

Private Sub richEditControl1_MouseMove(ByVal sender As Object, ByVal e As MouseEventArgs)
    Dim point As Point = e.GetPosition(CType(richEditControl1, UIElement))
    Dim pt As New System.Drawing.PointF(Units.PixelsToDocumentsF(CSng(point.X),richEditControl1.DpiX), Units.PixelsToDocumentsF(CSng(point.Y), richEditControl1.DpiY))
    Dim pos As DocumentPosition = richEditControl1.GetPositionFromPoint(pt)

    Dim bmCollection As BookmarkCollection = richEditControl1.Document.Bookmarks
    textBlock1.Text = String.Empty 'Clear a text block displaying bookmark info

    If pos IsNot Nothing Then
        For Each bm As Bookmark In bmCollection
            If bm.Range.Contains(pos) Then
                Dim bmHovered As Bookmark = bm
                richEditControl1.Document.SelectBookmark(bmHovered)
                ShowBookmarkInTextBlock(bmHovered)
                Exit For
            End If
        Next bm
    End If
End Sub

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the GetPositionFromPoint(PointF) 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.

See Also