Configuration:
- Windows 7
- .NET 3.5
- Visual Studio 2008
Summary: sending words to a rtb via a for-loop; format them based on their content ("OK" shown in green, "failed" shown in red).
Code:
for (int i = 0; i < inputValues.Length; i++)
{
//checking if the value is OK or not
string answer = functionReturningString(inputValues[i], referenceValue);
textBox4.Text += answer; //and sending the result string to text box
}
Now I'm simply trying to select the string that was added last and format it based on its content.
textBox4.SelectAll();
textBox4.Select(textBox4.SelectedText.Length - answer.Length, answer.Length);
if (answer == "OK")
{
textBox4.SelectionColor = Color.Green;
} else {
textBox4.SelectionColor = Color.Red;
}
textBox4.Refresh();//I want to see every value as soon as added
textBox4.Text += "\r\n"; //adding space between words
As for the result, it will eventually use the "SelectionColor" on all words in the rtb.
Q: How can I make sure the previously formatted words don't change their color again?
Update: The suggested solution didn't work either. Words will be displayed in their correct color (at first). Then the next word is added and the color of the whole box changes.