Hi !
I've been trying to color words in a RichTextBox in red. I made this and it works:
foreach (string sentence in splittedOriginalText)
{
richTextBox1.SelectionColor = Color.Black;
for (int i = 0; i < keywords.Length; i++)
{
if (keywords == sentence.ToLower())
{
richTextBox1.SelectionColor = Color.Red;
break;
}
}
richTextBox1.SelectedText = sentence + " ";
}
Now things have changed. I don't have any keywords to compare my words
to, but only the index of the words that need to be colored. I've been
trying, but somehow it won't work ... any idea to help me out here ?
Loading
Scott LyslePosted Jun 4, 2008, 11:46 PM
Well, you need to know the length of the work to select it so you can get the next index of the space between words to figure that; give this a shot (where rtbDoc is the richtextbox and the array contains the index positions you are looking for):
int[] arr = { 6, 24 };
int startPos = 0;
for (int i = 0; i < arr.Length; i++)
{
rtbDoc.Select(arr[i], rtbDoc.Text.IndexOf(" ", startPos));
startPos = rtbDoc.Text.IndexOf(" ", startPos);
rtbDoc.SelectionColor = Color.Red;
}