changing the colour of certain characters and count in RichTextBox
Here is code example:
private void ColorTheKs()
{
for(int i = 0; i< richTextBox1.Text.Length; i++)
{
if (richTextBox1.Text[i] == 'K')
{
richTextBox1.SelectionStart = i;
richTextBox1.SelectionLength = 1;
richTextBox1.SelectionColor = Color.Red;
richTextBox1.SelectionBackColor = Color.Yellow;
}
}
}
this example colors K letters in rich text box. Its not ideal but you'll get a point how you can color text.
Here is the result:
Try this.
richTextBox1.ForeColor = Color.Red;
精彩评论