Skip to main content
A newer version of this page is available. .

RichEditControl.GetPositionFromPoint(PointF) Method

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

Namespace: DevExpress.XtraRichEdit

Assembly: DevExpress.XtraRichEdit.v18.2.dll

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.

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);
}

The following code snippets (auto-collected from DevExpress Examples) contain references to the GetPositionFromPoint(PointF) method.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

See Also