无需选择即可更改richtext框文本颜色

时间:2014-03-21 16:02:37

标签: c#

我一直试图在我的文本框中为某些单词着色,例如" hi"," bye"

我尝过这样的话:

int stIndex = 0;
stIndex = richTextBox1.Find(wh, stIndex, RichTextBoxFinds.MatchCase);
while (stIndex != -1)
{
    if (richTextBox1.SelectedText == wh)
    {
        richTextBox1.SelectionLength = wh.Length;
        richTextBox1.SelectionColor = Color.Blue;
    }
    stIndex = richTextBox1.Find(wh, stIndex + 1, RichTextBoxFinds.MatchCase);
}

但选择单词因此移动光标有没有其他方法可以做到这一点?

0 个答案:

没有答案