"Ramsin Savra" <rsavra@otxresearch.com> wrote:
[color=blue]
>
>Hi, there are some question I have for you since I"m new to C# and still not
>familiar with some issues. However, please let me know why you used:
> textBox.SelectionStart = charIndex +Environment.NewLine.Length;
>
>What Environement.NewLine is ?[/color]
Here:
http://msdn.microsoft.com/library/de...wlinetopic.asp
It's a string - "\r\n" - which is what Windows uses to specify a "new line".
[color=blue]
>also why you put : charIndex += textBox.Lines[i].Length; ?[/color]
Here, charIndex is being incremented by the length of the current line.
[color=blue]
>my textbox has 10 lines but this makes it 14 and doesn't return a proper
>line number after exiting the end of loop the value is 43.[/color]
Sorry! I made an error -- I must've been half asleep when I wrote that.
Here's how it should look:
private void SetCursorToStartOfLine(int lineIndex)
{
int charIndex = 0;
for (int i = 0; i < textBox.Lines.Length && i < lineIndex - 1; ++i) {
charIndex += textBox.Lines[i].Length + Environment.NewLine.Length;
}
textBox.SelectionStart = charIndex;
}
[color=blue]
>any suggestions ?
>thanks in advance[/color]