我正在开发一个 Windows 窗体应用程序。我用RichTextBox.LoadFile
方法从文件加载文本并突出显示文本的某些部分。文件中的文本包含返回字符。
假设我想突出显示the highlight
。首先我找到startIndex
和length
of the the highlight
部分,然后使用RichTextBox.Select(startIndex, length)
并给它一些颜色。
当我使用SubString
方法,我可以找到正确的文本。但是当我应用相同的值时startIndex
and length
to Select
方法,突出显示的部分变成[space][space][space]the highli
。它看起来Select
方法考虑了一些返回字符并导致一些问题。
我该如何解决?
我认为你应该使用Find()
的方法RichTextBox
:
int nextStartIndex;
public void Find(string keyword){
int i = richTextBox1.Find(keyword, nextStartIndex, RichTextBoxFinds.None);
if(i != -1) {
nextStartIndex = i + keyword.Length;
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)