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.v23.2.dll

NuGet Packages: DevExpress.Win.PivotGrid, DevExpress.Win.RichEdit, DevExpress.Win.TreeMap

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 origin is located at the upper left corner of the RichEditControl. Use the Units.PixelsToDocuments method to translate coordinates.

The Point Coordinate Units

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.

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

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