Skip to main content

DevExpress v24.2 Update — Your Feedback Matters

Our What's New in v24.2 webpage includes product-specific surveys. Your response to our survey questions will help us measure product satisfaction for features released in this major update and help us refine our plans for our next major release.

Take the survey Not interested

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.

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.

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