/// <summary> /// Finds the range nearest to a screen coordinate. /// If the coordinate is within the bounding rectangle of a character then the /// range will contain that character. Otherwise, it will be a degenerate /// range near the point, chosen in an implementation-dependent manner. /// An InvalidOperation exception is thrown if the point is outside of the /// client area of the text container. /// </summary> /// <param name="screenLocation">The location in screen coordinates.</param> /// <returns>A degenerate range nearest the specified location.</returns> public TextPatternRange RangeFromPoint(Point screenLocation) { //If we are not within the client area throw an exception Rect rect = (Rect)_element.GetCurrentPropertyValue(AutomationElement.BoundingRectangleProperty); if (screenLocation.X < rect.Left || screenLocation.X >= rect.Right || screenLocation.Y < rect.Top || screenLocation.Y >= rect.Bottom) { throw new ArgumentException(SR.Get(SRID.ScreenCoordinatesOutsideBoundingRect)); } SafeTextRangeHandle hTextRange = UiaCoreApi.TextPattern_RangeFromPoint(_hPattern, screenLocation); return(TextPatternRange.Wrap(hTextRange, this)); }