If I call textBox.GetLineFromCharIndex(int) in a TextBox with WordWrap = true, it returns the line index as the user sees it (wrapped lines count as multiple lines), not the line according to the line breaks.
Line one extends to // <- word wrapped here. // <- logical line 1, GetLineFromCharIndex returns line 2 This is line two. // <- logical line 2, GetLineFromCharIndex returns line 3
Does anyone know of a solution to find the logical line from a character index rather than the displayed line?
Find the number of occurrences of newlines in the entire text up to your char index.
Perhaps first take the substring of the textbox’s text up to your char index. Use Split on newlines, and count the result.
Alternatively, a looping solution would use Index functions and count how many newlines are found up to your char index.