RichEditControl.GetPositionFromPoint(PointF) Method

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

Namespace: DevExpress.Xpf.RichEdit

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


public DocumentPosition GetPositionFromPoint(
    PointF clientPoint
Public Function GetPositionFromPoint(
    clientPoint As PointF
) As DocumentPosition


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.


Type Description

A DocumentPosition object representing a position in the document.


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 BookmarkCollection.Select method, and its name and text fragment are displayed in the text box below.

void richEditControl1_MouseMove(object sender, MouseEventArgs e)
    Point point = e.GetPosition((UIElement)richEditControl1);
    System.Drawing.PointF pt = new System.Drawing.PointF(Units.PixelsToDocumentsF((float)point.X,richEditControl1.DpiX),
        Units.PixelsToDocumentsF((float)point.Y, richEditControl1.DpiY));
    DocumentPosition pos = richEditControl1.GetPositionFromPoint(pt);

    BookmarkCollection bmCollection = richEditControl1.Document.Bookmarks;
    textBlock1.Text = String.Empty; //Clear a text block displaying bookmark info

    if (pos != null)
        foreach (Bookmark bm in bmCollection)
            if (bm.Range.Contains(pos))
                Bookmark bmHovered = bm;
See Also