windowsforms-6012-controls-and-libraries-rich-text-editor-examples-text-how-to-obtain-the-document-position-under-the-mouse-pointer.md
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.
Note
The measurement logic of RichEditControl uses the units specified by the RichEditControl.Unit property. If this property is set to a value other than DocumentUnit.Document, convert the point coordinates to the specified units. The Units class method allows you to convert between measurement units.
using DevExpress.Office.Utils;
using DevExpress.XtraRichEdit.API.Native;
using System.Drawing;
using System.Windows.Forms;
this.richEditControl1.MouseMove += richEditControl1_MouseMove;
void richEditControl1_MouseMove(object sender, MouseEventArgs e)
{
Point docPoint =
Units.PixelsToDocuments(e.Location, richEditControl1.DpiX, richEditControl1.DpiY);
DocumentPosition pos = richEditControl1.GetPositionFromPoint(docPoint);
if (pos != null)
this.Text = System.String.Format("Mouse is over position {0}",pos);
else this.Text = "";
}
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