当前位置: 首页 > news >正文

winfrom 查询某字符串 找到它在 richTextbox 的位置 定位 并高亮 并且滚动定位到所查询的字符串所在的行

如图:

代码:

 //查找关键字private void buttonSearch_Click(object sender, EventArgs e){string searchText = textBoxSearch.Text;if (!string.IsNullOrEmpty(searchText)){TextBoxFinds(txtJSON, searchText);TextBoxFinds(txtSQL, searchText);}}//查找关键字,关键字高亮,并且定位到关键字处public void TextBoxFinds(RichTextBox richTextBox, string searchText){try{// 清除之前的高亮显示richTextBox.SelectAll();richTextBox.SelectionBackColor = Color.White;richTextBox.SelectionColor = Color.Black;// 查找字符串int index = richTextBox.Find(searchText);if (index != -1){// 高亮显示找到的字符串richTextBox.Select(index, searchText.Length);richTextBox.SelectionBackColor = Color.Yellow;richTextBox.SelectionColor = Color.Black;// 获取找到的字符串所在的行int line = richTextBox.GetLineFromCharIndex(index);// 滚动到该行int firstCharIndex = richTextBox.GetFirstCharIndexFromLine(line);richTextBox.SelectionStart = firstCharIndex;richTextBox.ScrollToCaret();}}catch { }}

相关文章:

  • Meltdown原理介绍:用户空间读取内核内存
  • apt3.0和apt2.0的区别
  • AI数字人分身无限克隆,开启IP视频创作新纪元!
  • 如何判断一个js对象是否拥有某个属性(区分自身属性和原型链上的属性)?
  • [管理与领导-129]:向上管理-组织架构、股权架构、业务架构、流程架构,看每个人在组织中的位置和重要性
  • Angular 框架详解:从入门到进阶
  • 数据库主从复制
  • 解决Ubuntu终端命令不能补全的问题
  • Linux:解决 yum 官方源无法使用(CentOS 7)
  • postman使用技巧
  • Postman做自动化测试
  • opencv函数展示
  • 【数字图像处理】数字图像空间域增强(3)
  • WIFI扫描记录
  • Spark-SQL核心编程(二)(三)
  • LIB-ZC, 一个跨平台(Linux)平台通用C/C++扩展库, IO操作
  • 管理与维护samba服务器
  • 信创服务器-大国崛起,信创当道!
  • SpringBoot异常处理之自定义统一的错误处理页面
  • 大模型全景解析:从技术突破到行业变革
  • 网站备案怎么弄/信阳seo公司
  • 毕业设计代做网站多少钱/seo标题优化关键词怎么选
  • 短网址生成链接/网站关键词怎么优化到首页
  • 做问卷哪个网站好/百度推广个人怎么开户
  • 加人引流加人网站怎么做/百度知道个人中心
  • 石家庄网站制作机构/seoshanghai net