How to: Obtain the Document Position under the Mouse Cursor

The RichEditControl allows you to determine the position in the document that corresponds to any given point with known screen coordinates. To accomplish this task, use the RichEditControl.GetPositionFromPoint method.

The document position which the mouse pointer hovers over, is displayed in the form title bar.

Imports DevExpress.Office.Utils
Imports DevExpress.XtraRichEdit.API.Native
Imports System.Drawing
Imports System.Windows.Forms
            AddHandler Me.richEditControl1.MouseMove, AddressOf richEditControl1_MouseMove
        Private Sub richEditControl1_MouseMove(ByVal sender As Object, ByVal e As MouseEventArgs)
            Dim docPoint As Point = Units.PixelsToDocuments(e.Location, richEditControl1.DpiX, richEditControl1.DpiY)
            Dim pos As DocumentPosition = richEditControl1.GetPositionFromPoint(docPoint)
            If pos IsNot Nothing Then
                Me.Text = System.String.Format("Mouse is over position {0}",pos)
            Else
                Me.Text = ""
            End If
        End Sub