ICSharpCode.TextEditor 实现查找功能

 int startindex = 0;
 private void toolFind_Click(object sender, EventArgs e)
 {
	 //设置选择的文本。
	 var text =  this.txtFindText.Text;//取得要查找的文本
	 var offset = this.CodeEditor.Text.IndexOf(text, startindex,StringComparison.CurrentCultureIgnoreCase);
	 if (offset >= 0)
	 {
	     startindex = offset + text.Length;//为查找下一个做准备
	     var start = this.CodeEditor.Document.OffsetToPosition(offset);
	     var end = this.CodeEditor.Document.OffsetToPosition(offset + text.Length);
	     this.CodeEditor.ActiveTextAreaControl.SelectionManager.SetSelection(new DefaultSelection(this.CodeEditor.Document, start, end));
	
	     //滚动到选择的位置。
	     this.CodeEditor.ActiveTextAreaControl.Caret.Position = end;
	     this.CodeEditor.ActiveTextAreaControl.TextArea.ScrollToCaret();
	 } else {
	     startindex = 0;//循环查找
	 }
}