How to: Obtain the Document Position under the Mouse Pointer

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.

View Example

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 = "";
        }