How can I get the cursor column number in a TextBox in C #?

I have a multiline text block that would like to have a label in the form displaying the current position of the row and column, as Visual Studio does.

I know I can get row # with GetLineFromCharIndex, but how can I get column # on this row?

(I really want the cursor position on this row, not the "column", by itself)

+6
user-interface c # windows
source share
3 answers
int line = textbox.GetLineFromCharIndex(textbox.SelectionStart); int column = textbox.SelectionStart - textbox.GetFirstCharIndexFromLine(line); 
+9
source share
 textBox.SelectionStart - textBox.GetFirstCharIndexFromLine(textBox.GetLineFromCharIndex(textBox.SelectionStart)) 
+2
source share

On top of my head, I think you want the SelectionStart property.

0
source share

All Articles