private void HilightRichText(RichTextBox control, string hilightString)
        {
            int nSelectStart = control.SelectionStart;  
            int nSelectLength = control.SelectionLength;
            int nIndex = 0;
            while (nIndex < control.Text.Length)
            {
                nIndex = control.Find(hilightString, nIndex, RichTextBoxFinds.WholeWord); //整个文档查找
                if (nIndex < 0)
                {
                    break;                     
                }
                control.Select(nIndex, hilightString.Length);      //选择文本
                control.SelectionColor = Color.Red;
                nIndex += hilightString.Length;
            }
            control.Select(nSelectStart, nSelectLength);
        }

posted on 2016-12-17 10:06  铭记321  阅读(1252)  评论(0编辑  收藏  举报