GetCharIndexFromPosition() public méthode

public GetCharIndexFromPosition ( Point pt ) : int
pt Point
Résultat int
            /// <summary>
            ///  Returns the degenerate (empty) text range nearest to the specified screen coordinates.
            /// </summary>
            /// <param name="screenLocation">The location in screen coordinates.</param>
            /// <returns>A degenerate range nearest the specified location. Null is never returned.</returns>
            public override UiaCore.ITextRangeProvider?RangeFromPoint(Point screenLocation)
            {
                if (!_owningTextBoxBase.IsHandleCreated)
                {
                    return(null);
                }

                Point clientLocation = screenLocation;

                // Convert screen to client coordinates.
                // (Essentially ScreenToClient but MapWindowPoints accounts for window mirroring using WS_EX_LAYOUTRTL.)
                if (MapWindowPoint(IntPtr.Zero, _owningTextBoxBase, ref clientLocation) == 0)
                {
                    return(new UiaTextRange(_owningTextBoxBase.AccessibilityObject, this, start: 0, end: 0));
                }

                // We have to deal with the possibility that the coordinate is inside the window rect
                // but outside the client rect. In that case we just scoot it over so it is at the nearest
                // point in the client rect.
                RECT clientRectangle = _owningTextBoxBase.ClientRectangle;

                clientLocation.X = Math.Max(clientLocation.X, clientRectangle.left);
                clientLocation.X = Math.Min(clientLocation.X, clientRectangle.right);
                clientLocation.Y = Math.Max(clientLocation.Y, clientRectangle.top);
                clientLocation.Y = Math.Min(clientLocation.Y, clientRectangle.bottom);

                // Get the character at those client coordinates.
                int start = _owningTextBoxBase.GetCharIndexFromPosition(clientLocation);

                return(new UiaTextRange(_owningTextBoxBase.AccessibilityObject, this, start, start));
            }
 /// <remarks>
 /// GetCharIndexFromPosition is missing one caret position, as there is
 /// one extra caret position than there are characters (an extra one at
 /// the end). See http://stackoverflow.com/a/3874132.
 /// </remarks>
 public static int GetCaretIndex(TextBoxBase @this, Point point)
 {
     point = @this.PointToClient(point);
     var index = @this.GetCharIndexFromPosition(point);
     if (index == (@this.TextLength - 1))
     {
         var caretPoint = @this.GetPositionFromCharIndex(index);
         if (caretPoint.X < point.X) index += 1;
     }
     return index;
 }
			public ICollection<HotSpotInternal> GetHotSpotsFromPosition(TextBoxBase textBox, Point position) {
				int offset = textBox.GetCharIndexFromPosition(position);

				return GetHotSpotsFromOffset(offset);
			}