Skip to main content

RichEditControl.GetPositionFromPoint(PointF) Method

Gets the position in the document closest to the specified point.

Namespace: DevExpress.XtraRichEdit

Assembly: DevExpress.XtraRichEdit.v22.2.dll

NuGet Package: DevExpress.Win.RichEdit

Declaration

public DocumentPosition GetPositionFromPoint(
    PointF clientPoint
)

Parameters

Name Type Description
clientPoint PointF

A PointF object that specifies a point in the RichEditControl window.

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 (Nothing in 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.

Note

If you handle the DragDrop, DragEnter, or DragOver event, an additional conversion step is required. The X and Y properties of the DragEventArgs are in screen coordinates, not client coordinates. Use the PointToClient method of the RichEditControl to convert a point with coordinates taken from the DragEventArgs to client coordinates

Example

The following code gets the mouse position and displays coordinates in a tooltip.

The RichEditControl instance is passed to the BarItem.ItemClick event handler using the BarItem.Tag property.

View Example

static DevExpress.Utils.ToolTipController testToolTipController = new DevExpress.Utils.ToolTipController();

static void richEditControl1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e) {
    RichEditControl richEdit = sender as RichEditControl;
    System.Drawing.Point docPoint = 
        DevExpress.Office.Utils.Units.PixelsToDocuments(e.Location, richEdit.DpiX, richEdit.DpiY);

    DocumentPosition pos = richEdit.GetPositionFromPoint(docPoint);
    if(pos == null) return;
    string currentToolTipText = String.Format("Position: {0}, Character: {1}", pos.ToString(), 
        richEdit.Document.GetText(richEdit.Document.CreateRange(pos, 1)));

    DevExpress.Utils.ToolTipControlInfo info = 
        new DevExpress.Utils.ToolTipControlInfo(currentToolTipText, currentToolTipText);
    info.ToolTipPosition = System.Windows.Forms.Form.MousePosition;
    testToolTipController.ShowHint(info);
}
See Also