温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

ComponentOne C1Editor 中高亮查找文字

发布时间:2020-04-09 06:00:26 来源:网络 阅读:364 作者:C1SupportTeam 栏目:编程语言

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

截图展示:

ComponentOne C1Editor 中高亮查找文字cdn.grapecity.com/p_w_upload.aspx?p_w_uploadid=2344">

Demo 下载

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

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

 

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI