I'm having difficulty creating a code that able to pick up specific words and color them. I'm currently using this code:
private void Colorize(string word, Color color, int startIndex)
{
if (this.richTextBox1.Text.Contains(word))
{
int index = -1;
int selectStart = this.richTextBox1.SelectionStart;
while ((index = this.richTextBox1.Text.IndexOf(word, (index + 1))) != -1)
{
this.richTextBox1.Select((index + startIndex), word.Length);
this.richTextBox1.SelectionColor = color;
this.richTextBox1.Select(selectStart, 0);
this.richTextBox1.SelectionFont = new Font(richTextBox1.Font, FontStyle.Regular);
this.richTextBox1.SelectionColor = Color.Black;
}
this.richTextBox1.SelectionColor = Color.Black;
}
}
The problem is that when the text of the RichTextBox is too large it hangs and runs from top to bottom, is there any way to instantly color keywords? I'm doing a basic IDE, but I need some color java-based keywords.
Any error sorry I used the google translator.