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.v20.2.dll

NuGet Packages: DevExpress.WindowsDesktop.Wpf.RichEdit, DevExpress.Wpf.RichEdit

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

View Example

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;
                richEditControl1.Document.SelectBookmark(bmHovered);
                ShowBookmarkInTextBlock(bmHovered);
                break;
            }
        }
    }
}

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