tags:

views:

639

answers:

4

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)

A: 

Is this a textbox or a datagrid view? Cause with text box you only have one column....

peregrine
A: 

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

Joel Coehoorn
+1  A: 
textBox.SelectionStart -
textBox.GetFirstCharIndexFromLine(textBox.GetLineFromCharIndex(textBox.SelectionStart))
Omer van Kloeten
Perfect. This is exactly what I wanted. Thanks.
RyanE
+4  A: 
int line = textbox.GetLineFromCharIndex(textbox.SelectionStart);
int column = textbox.SelectionStart - textbox.GetFirstCharIndexFromLine(line);
DamienG