Reputation: 3181
I need to highlight specific text inside richtext box during runtime, based on a condition. I tried to replace the text with a text with html tags but it didn't render it.
How can I do that?
Upvotes: 1
Views: 187
Reputation: 1342
You can try something like this . Offcourse, change the code depending on your condition.
private void button1_Click(object sender, EventArgs e)
{
if (richTextBox1.Text.Contains("red"))
{
richTextBox1.SelectionStart = 0;
richTextBox1.SelectionLength = richTextBox1.Text.Length;
richTextBox1.SelectionBackColor = Color.Black;
richTextBox1.SelectionColor = Color.White;
}
}
Upvotes: 2