GetPositionFromCharIndex() public méthode

public GetPositionFromCharIndex ( int index ) : Point
index int
Résultat Point
 /// <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;
 }
        /// <summary>
        /// Sets the location of the AutoComplete form, maiking sure it's on the screen where the cursor is.
        /// </summary>
        /// <param name="moveHorizontly">determines wheather or not to move the form horizontly.</param>
        private void SetAutoCompleteLocation(TextBoxBase control, bool moveHorizontly)
        {
            Point cursorLocation = control.GetPositionFromCharIndex(control.SelectionStart);
            Screen screen = Screen.FromPoint(cursorLocation);
            Point optimalLocation = new Point(PointToScreen(cursorLocation).X - 15, (int)(PointToScreen(cursorLocation).Y + Font.Size * 2 + 2));
            Rectangle desiredPlace = new Rectangle(optimalLocation, this.Size);
            desiredPlace.Width = 152;
            if (desiredPlace.Left < screen.Bounds.Left)
            {
                desiredPlace.X = screen.Bounds.Left;
            }
            if (desiredPlace.Right > screen.Bounds.Right)
            {
                desiredPlace.X -= (desiredPlace.Right - screen.Bounds.Right);
            }
            if (desiredPlace.Bottom > screen.Bounds.Bottom)
            {
                desiredPlace.Y = cursorLocation.Y - 2 - desiredPlace.Height;
            }
            if (!moveHorizontly)
            {
                desiredPlace.X = this.Left;
            }

            this.Bounds = desiredPlace;
        }
        private System.Drawing.Point GetCurrentCoordinates(TextBoxBase control)
        {
            // note, get rid of the "+1" if you want the coordinates to be zero based
            //Point p = new System.Drawing.Point();
            //p.Y = (rtb.GetLineFromCharIndex(rtb.SelectionStart)) + 1;
            //p.X = (rtb.SelectionStart - rtb.GetFirstCharIndexOfCurrentLine()) + 1;
            Point point = control.GetPositionFromCharIndex(control.SelectionStart);
            // FIX for textbox
            if(point.X ==0 && point.Y == 0)
            {
                if (control.SelectionStart > 0)
                {
                    point = control.GetPositionFromCharIndex(control.SelectionStart - 1);
                }
            }

            return point;
        }
 public override Point GetPositionFromChar(int charIndex)
 => _owningTextBoxBase.IsHandleCreated
         ? _owningTextBoxBase.GetPositionFromCharIndex(charIndex)
         : Point.Empty;
		private static Point GetPositionFromCharIndex(TextBoxBase textBox, int offset)
		{
			Point position = textBox.GetPositionFromCharIndex(offset);
			// the following is necessary to work around a .Net bug
			int x = (Int16) position.X;
			int y = (Int16) position.Y;
			return new Point(x, y);
		}