Nitin S
Nitin S

Reputation: 7601

How to move cursor to first position in last line of RichTextBox?

For moving cursor to last position I am using following code(which works fine)

rtbLog.SelectionStart = rtbLog.Text.Length;
rtbLog.ScrollToCaret();

How to move cursor to first position in last line of RichTextBox?

Upvotes: 0

Views: 2084

Answers (1)

StaWho
StaWho

Reputation: 2488

You can do it using last index of Environment.Newline:

rtbLog.SelectionStart = rtbLog.Text.LastIndexOfAny(Environment.NewLine.ToCharArray()) + 1 ;
rtbLog.ScrollToCaret();

Upvotes: 2

Related Questions