let's say I have a RichTextbox that contains the following text:
Error
Warning
Info
And let's say I want to change the last word's color to green.
How would I do that? I do have some code to change the color of some text (a replace function), but all I want is to ONLY change the latest line if you know what I mean...
I almost forgot, here is the code that I use to change the word's colors:
static void ReplaceText(RichTextBox box, string phrase, Color color)
{
box.HideSelection = true;
int pos = box.SelectionStart;
string s = box.Text;
for (int ix = 0; ; )
{
int jx = s.IndexOf(phrase, ix, StringComparison.CurrentCultureIgnoreCase);
if (jx < 0) break;
box.SelectionStart = jx;
box.SelectionLength = phrase.Length;
box.SelectionColor = color;
ix = jx + 1;
}
box.SelectionStart = pos;
box.SelectionLength = 0;
}
So in other words, how do I ONLY edit the latest line? Thanks!
EDIT: BTW! The colors need to stay there, it's let's say a console output window.