/// <summary> /// Ermittelt die Position des Carets für den angegebenen Punkt /// </summary> /// <param name="textBox">das Eingabefeld, dessen Caret-Position ermittelt werden soll</param> /// <param name="point">der Punkt, für den die Caret-Position ermittelt werden soll</param> /// <returns></returns> public static int GetCaretIndexFromPoint(this TextBoxBase textBox, Point point) { Point actualPoint = textBox.PointToClient(point); int index = textBox.GetCharIndexFromPosition(actualPoint); if (index == textBox.Text.Length - 1) { Point caretPoint = textBox.GetPositionFromCharIndex(index); if (actualPoint.X > caretPoint.X) { index += 1; } } return(index); }