I tried to use this method, but it changes only the first time that textToMark
is shown in the richTextBox
and I want it to change every time textToMark
is contained:
public static void ChangeTextcolor(string textToMark, Color color, RichTextBox richTextBox)
{
int startIndex = 0;
string text = richTextBox.Text;
startIndex = text.IndexOf(textToMark);
System.Drawing.Font newFont = new Font("Verdana", 10f, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, 178, false);
try
{
foreach (string line in richTextBox.Lines)
{
if (line.Contains(textToMark))
{
richTextBox.Select(startIndex, textToMark.Length);
richTextBox.SelectionColor = color;
richTextBox.SelectionFont = newFont;
}
}
}
catch{ }
}
Can you help me? Thanks