Get Line & Column RichTextBox
Looks good. Thanks.
Here's my final solution, in case anyone in the future will need it.
At the end of the following code, iLine contains the caret's line number and iCol contains the column.
int iLine = richTextBox1.GetLineFromCharIndex(richTextBox1.SelectionStart) + 1;
int iOffset = 0;
for (int i = 0; i < iLine - 1; ++i)
{
iOffset += richTextBox1.Lines[i].Length + 1;
}
int iCol = richTextBox1.SelectionStart - iOffset;
Re: Problem with RichTextBox
WOW Thankyou I have been trying to figure out how to do this for three days lol :) I finally realized how to spell caret lol and boom here it is thankyou thankyou thankyou p.s. I slightly changed the code as I wanted to mimic notepad and the col was off by 1 so your code said that the col is 0 when it actually is 1 below is my code :)
P.S. Thankyou again :)
int iLine = richTextBox1.GetLineFromCharIndex(richTextBox1.SelectionStart) + 1;
int iOffset = 0;
for (int i = 0; i < iLine - 1; ++i)
{
iOffset += richTextBox1.Lines[i].Length + 1;
}
int iCol = (richTextBox1.SelectionStart - iOffset) + 1;
this.statusBarPanel2.Text = "Ln " + iLine + ", Col " + iCol;
oh did I say thankyou :)
I found this link but it was way to much code and yes this code is nice and neat :)
http://www.codeguru.com/Csharp/Cshar...int.php/c8145/
and my link to my post on this site was here :)
http://www.codeguru.com/forum/showth...69#post1105669
Thankyou again
I do have one small problem I put it into the _MouseDown and the _KeyPress works great except when I use the arrow keys and the delete key ext... is there one spot that I can put it where it will work whether or not its a mouse click or a key pressed (All keys relevent including arrow keys ext...)
Help