System.Windows.Forms.TextBoxBase.GetCharIndexFromPosition C# (CSharp) Method

GetCharIndexFromPosition() public method

public GetCharIndexFromPosition ( Point pt ) : int
pt Point
return int
		public virtual int GetCharIndexFromPosition (Point pt)
		{
			return (int)m_helper.TextView.CharacterIndex(pt);
			                 
		}
		//TODO:

Usage Example

            /// <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));
            }
All Usage Examples Of System.Windows.Forms.TextBoxBase::GetCharIndexFromPosition