/// <summary>
        /// Retrieves the range of a child object.
        /// </summary>
        /// <param name="childElement">The child element.  If the element is not
        /// a child of the text container then an InvalidOperation exception is
        /// thrown.</param>
        /// <returns>A range that spans the child element.</returns>
        public TextPatternRange RangeFromChild(AutomationElement childElement)
        {
            if (childElement == null)
            {
                throw new ArgumentNullException("childElement");
            }
            SafeTextRangeHandle hTextRange = UiaCoreApi.TextPattern_RangeFromChild(_hPattern, childElement.RawNode);

            return(TextPatternRange.Wrap(hTextRange, this));
        }
        /// <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));
        }