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);
        }

WinForm richtextbox 关键字变红色的更多相关文章

  1. javascript点击变绿色再点击变红色

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  2. WPF RichTextBox,关键字搜索,样式改变,超链接替换,图文混排

    RichTextBox 只是一个控件,表示对 FlowDocument 对象执行操作的丰富编辑控件.它所承载的内容由其 Document 属性来呈现. Document 是一个 FlowDocumen ...

  3. WinForm RichTextBox 常用操作

    1.设置不自动选择字词 RichTextBox在选择文字的时候,如果没有关闭自动选择字词功能,我们有时候选择的时候会自动将光标前后的字或者词连接在一起进行选择. RichTextBox有属性AutoW ...

  4. CSS 确定选中变红色

    textarea:focus { border: 1px solid #f4645f; outline: none; } blockquote { border-left: 4px solid #f4 ...

  5. c# winform richtextbox控制每行颜色 + 滚动条始终滚动到最底部

    /// <summary> /// 输出 /// </summary> /// <param name="content"></param ...

  6. 解决方案:Resharper对系统关键字提示‘can not resolve symbol XXX’,并且显示红色,但是编译没有问题

    环境:Visual studio 2013 community update 4 + Resharper 8.2 + Windows 7现象:我的C#工程编译没有问题, 但是在代码编辑器中系统关键字显 ...

  7. 【转载】解决方案:Resharper对系统关键字提示‘can not resolve symbol XXX’,并且显示红色,但是编译没有问题

    环境:Visual studio 2013 community Update 4 + Resharper 8.2 + Windows 7 现象: 我的C#工程编译没有问题, 但是在代码编辑器中系统关键 ...

  8. 10月30日下午 PHP精确查询(模糊查询、模糊+关键字共同查询)

    1.一个条件的模糊查询 <body> <br /> <form action="main.php" method="post"&g ...

  9. SQL关键字转换大写核心算法实现

    1 不跟你多废话 上代码! /// <summary> /// SQL关键字转换器 /// </summary> public class SqlConverter : IKe ...

随机推荐

  1. [转载]Python 资源大全

    原文链接:Python 资源大全 环境管理 管理 Python 版本和环境的工具 p – 非常简单的交互式 python 版本管理工具. pyenv – 简单的 Python 版本管理工具. Vex  ...

  2. mybatiGenerator

    <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE generatorConfiguratio ...

  3. Js日期函数Date格式化扩展

    prototype是向对象中添加属性和方法,返回对象类型原型的引用,例如对js中日期函数Date进行扩展: Date.prototype.Format = function (fmt) { var o ...

  4. PowerDesigner 逆向中 Name和Comment互换

    在使用PowerDesigner对数据库进行概念模型和物理模型设计时,一般在NAME或Comment中写中文,在Code中写英文.Name用来显 示,Code在代码中使用,但Comment中的文字会保 ...

  5. Tomcat部署web项目,虚拟目录,上下文(Context),WEB-INF,web.xml,servlet,404

    Web项目的uri模型大致如下: http://localhost:8080 (/context) (/resource) 站点/上下文/资源 一. Tomcat中指定上下文(Context) 方法一 ...

  6. 简单的VC++ ADO帮助类

    首先看头文件 #pragma once #import "c:\Program Files\Common Files\System\ado\msado15.dll" no_name ...

  7. ECshop 数据库表结构

    -- 表的结构 `ecs_account_log`CREATE TABLE IF NOT EXISTS `ecs_account_log` (`log_id` mediumint(8) unsigne ...

  8. Time.MONTH及Calendar.MONTH 默认的月份为 0-11

    Time.MONTH及Calendar.MONTH 默认的月份为  0-11 所以使用的时候要自己加1.

  9. 虚拟机virtualBox设置共享文件后,linux配置

    1.在/mnt下创建共享目录 mkdir /mnt/share 2.关联外部目录 mount -t vboxsf 共享文件夹名 /mnt/share/ 如:mount -t vboxsf BaiduS ...

  10. MLA Handbook for Writers of Research Papers笔记

    MLA Handbook for Writers of Research Papers.7th ed.New York:MLA,2009.print.还有一本,留待阅读MLA Style Manual ...