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;
}
}
}
}创新互联www.cdcxhl.cn,专业提供香港、美国云服务器,动态BGP最优骨干路由自动选择,持续稳定高效的网络助力业务部署。公司持有工信部办法的idc、isp许可证, 机房独有T级流量清洗系统配攻击溯源,准确进行流量调度,确保服务器高可用性。佳节活动现已开启,新人活动云服务器买多久送多久。