ComponentOne C1Editor 中高亮查找文字

ComponentOne C1Editor 是类似于 MS Word 和 MS FrontPage 文字编辑控件。用户可以使用 C1Editor 接口去搜索文字。所以,通常用户想实现搜索结果
高亮的效果。这篇文章将通过代码介绍怎么使用 C1Editor 搜索并且高亮搜索结果。

参考代码:

            
            int length = this.c1Editor1.Text.Length;
            string searchString = this.textBox1.Text;
            int searchStringLen = searchString.Length;
            int result = 0;
            if (searchStringLen > 0)
            {
                for (int i = 0; i <= length; i++ )
                {
                    c1Editor1.SelectionStart = c1Editor1.SelectionStart + searchStringLen;
                    if ((i + searchStringLen) <= length)
                    {
                        //compare the text searched with the substring of the C1Editor
                        if (c1Editor1.Text.Substring(i, searchStringLen).ToLower() == searchString.ToLower())
                        {
                            c1Editor1.Select(i, searchStringLen);
                            //set the backcolor of each occurrence of the word in C1Editor
                            c1Editor1.Selection.ApplyStyle("background-color", "Red");
                            result = result + 1;
                        }
                    }
                }
            }

截图展示:

Demo 下载

 

很高兴能和大家分享 ComponentOne 的使用方法、讨论 ComponentOne 使用过程中遇到的问题。

葡萄城控件产品网站:http://www.gcpowertools.com.cn/ 
      葡萄城技术支持论坛:http://gcdn.grapecity.com/

 

转载于:https://www.cnblogs.com/C1SupportTeam/archive/2012/07/18/2597511.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值