开发者

changing the colour of certain characters and count in RichTextBox

i have to count the number of a certain character in a C# richtextbox (namely: "K").

but i also want to give that character a colour in the rich text box when a button is pressed. in short, i'm in a bind, any help is appreci开发者_JS百科ated.

p.s: i tried googleing it but couldn't find a statisfactory solution.

my thanks in advance.


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:

changing the colour of certain characters and count in RichTextBox


Try this.

richTextBox1.ForeColor = Color.Red;

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜