我找不到那个函数。基本上,我有一个多行文本框,当我执行搜索时,我会突出显示结果。但如果结果不在视图范围内,我将不得不手动向下滚动,直到找到突出显示的结果,这超出了“查找”功能的目的。
我不想使用RichTextBox,因为我在使用它时遇到了一些性能问题。
发布于 2012-11-29 16:33:56
您可以将GetLineIndexFromCharacterIndex
与ScrollToLine
结合使用
var selectionStart = x;
var selectionLength = y;
textBox.Select(selectionStart, selectionLength);
textBox.ScrollToLine(textBox.GetLineIndexFromCharacterIndex(textBox.SelectionStart));
发布于 2016-10-13 08:48:49
ScrollToLine对我来说还不够准确。我的文本框启用了换行,所以行索引不可靠。取而代之的是我使用了这个:
textBox.CaretIndex = selectionStart;
textBox.ScrollToEnd();
textBox.Select(selectionStart, selectionLength);
基本上,ScrollToEnd会滚动到插入符号。
https://stackoverflow.com/questions/13621549
复制相似问题