C#;将滚动条移动到搜索词的位置
c#; Move the scroll bar to the location of the searched word
我编写了在 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();
我编写了在 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();