How can I get the final of the line in a RichTextBox?

DevilAkuma

Active member
Joined
Oct 24, 2005
Messages
37
Programming Experience
Beginner
Hello!

I'm working inside of a RichTextBox, and I need to change the color of a specific text. I can get the start very easy...

VB.NET:
 Dim start As Integer = myRichTextBox.Find("text",0)
But I don't know how can I get the final of the line.

I've tried searching for the next carriage return...

VB.NET:
 Dim end As Integer = myRichTextBox.Find(Chr(13),start))
But this doesn't work :( because (I don't know why) the RichTextBox keeps my new Color and It used to color the rest of the text... I select & colour the text with...

VB.NET:
myRichTextBox.Select(start,end)
myRichTextBox.SelectionColor = Color.Green

But the text is changed until the end of all...

Smeone knowshow can i do it?

Thanks in advance (and sorry about my English)
 
Last edited:
I've done it!

With this code runs so well :)

VB.NET:
Dim start As Integer = MyRichTextBox.Find("text", RichTextBoxFinds.None)
Dim end As Integer = MyRichTextBox.Find(vbCr, start, RichTextBoxFinds.None)
MyRichTextBox.SelectionStart() = start
MyRichTextBox.SelectionLength = end - start
MyRichTextBox.SelectionColor = Color.Red

Thanks!
 
Back
Top