如何滚动到富文本框中的字符串

时间:2021-11-01 15:23:39

I ahve a RTB with sufficent text that scrolling is needed
user enters a string and I highlight all occurrences using a combination of Find and Select which is great but now I want the ability for a user to press Next and the next higlighted instance should be visible say 2at /3rd of the bounding rectangle ( I would even settle for at the top of the bound.

我有一个带有足够文本的RTB,需要滚动用户输入一个字符串,我使用Find和Select的组合突出显示所有事件,这很好,但现在我希望用户能够按Next,下一个突出显示的实例应该是可见的比如边界矩形的2at / 3rd(我甚至会在边界顶部找到它。

How do I scroll to an index basically ( I am caching the indices as I find and markup )

我如何基本上滚动到一个索引(我正在缓存索引,因为我发现和标记)

oh also this is C# Winforms .NET 2.0

哦,这也是C#Winforms .NET 2.0

2 个解决方案

#1


4  

Set the selection start to the next location, and then use ScrollToCaret to scroll to that location in the rich text box.

将选择开始设置为下一个位置,然后使用ScrollToCaret滚动到富文本框中的该位置。

rText1.SelectionStart = i
rText1.ScrollToCaret()

#2


1  

private void myrichTextBox_TextChanged(object sender, EventArgs e)
{
   myrichTextBox.SelectionStart = myrichTextBox.Text.Length; //Set the current caret position             at the end
   myrichTextBox.ScrollToCaret(); //Now scroll it automatically
}

#1


4  

Set the selection start to the next location, and then use ScrollToCaret to scroll to that location in the rich text box.

将选择开始设置为下一个位置,然后使用ScrollToCaret滚动到富文本框中的该位置。

rText1.SelectionStart = i
rText1.ScrollToCaret()

#2


1  

private void myrichTextBox_TextChanged(object sender, EventArgs e)
{
   myrichTextBox.SelectionStart = myrichTextBox.Text.Length; //Set the current caret position             at the end
   myrichTextBox.ScrollToCaret(); //Now scroll it automatically
}