[英]RichTextbox Find
我找到了一個很好的搜索解決方案,並在RichTextbox LINK中突出顯示了文本
此解決方案效果很好,但是我發現了一個非常討厭的錯誤,當在任何文本(例如“ Hello World”)中搜索最后一個字符時,如果嘗試在搜索字段中鍵入字母“ d”,程序將無休止地出現故障。在這里循環
while ((index = this.Find(findWhat, startSearch, findoptions)) > -1)
{
isfind = true;
this.SelectionBackColor = highlightColor;
startSearch = index + 1;
}
如何解決這個錯誤? 或者,也許可以幫助我找到另一種解決方案,該方法如何在RichTextBox
查找和突出顯示文本。
是的,這是越野車。 您必須添加額外的檢查,以確保它不會在文本末尾之外開始搜索。 像這樣:
int max = this.TextLength;
while (startSearch < max &&
(index = this.Find(findWhat, startSearch, findoptions)) > -1) {
isFind = true;
this.SelectionBackColor = highlightColor;
startSearch = index + 1;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.