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

By : RyanE

I've got a multiline textBox that I would like to have a label on the form displaying the current line and column position of, as Visual Studio does.

I know I can get the line # with GetLineFromCharIndex, but how can I get the column # on that line?

(I really want the Cursor Position on that line, not 'column', per se)

By : RyanE

int line = textbox.GetLineFromCharIndex(textbox.SelectionStart);
int column = textbox.SelectionStart - textbox.GetFirstCharIndexFromLine(line);
By : DamienG

textBox.SelectionStart -

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

This video can help you solving your question :)
By: admin