c# - C#; 将滚动条移动到搜索词的位置
问题描述
我编写了在richtextbox 中查找单词的代码。现在,我想将滚动条移动到搜索词的位置。请帮我!!!
int j,count = 0;
string keyword = txtSearchByWords.Text;
int startPosition = 0; //initializing starting position to search
int endPosition = 0;
int endArticle = rtbWords.Text.Length;
for (j = 0; j < endArticle; j = startPosition)//creating a loop until ending the article
{
if (j == -1) //if the loop goes to end of the article then stop
{
break;
}
startPosition = rtbWords.Find(keyword, startPosition, endArticle, RichTextBoxFinds.WholeWord);
if (startPosition >= 0) //if match the string
{
count++;//conunting the number of occuerence or match the search string
rtbWords.SelectionBackColor = Color.Orange;//coloring the matching string in the article
endPosition = txtSearchByWords.Text.Length;
startPosition = startPosition + endPosition;//place the starting position at the next word of previously matching string to continue searching.
}
解决方案
使用 ScrollToCaret 滚动到富文本框中搜索词的位置
rText.SelectionStart = rtext.Text.Length;//set the start location
rText.ScrollToCaret();
推荐阅读
- python - 如何控制一个 html 中显示的项目数?
- javascript - 有条件地隐藏所有帖子上的 div,但不隐藏类别页面
- infinispan - 用于集群企业应用程序的 jboss 数据网格 - 什么是有效的方法
- android - 如何在 appcelerator android 应用程序中显示 admob 广告
- react-native - 反应原生线性渐变
- javascript - javascript phonegap条码扫描器太慢了
- javascript - 用 Javascript 修改组件模式数据值?
- ios - ios - 缺少必需的模块:“加密”
- linux - 如何为 Ubuntu 软件包创建本地存储库,这将与 by-hash 功能一起使用
- hyperledger-composer - 在部署现有业务网络时出现 Sysntax 错误