[英]How can I unselect text after it has been highlighted?
The code below highlights the text after it is found, but my issues is I can't clear the the highlighted text when you search for a word that cant be found. 下面的代码在找到后会突出显示文本,但是我的问题是,当您搜索找不到的单词时,我无法清除突出显示的文本。
My question is how do I set the selection to empty so the text is no longer highlighted? 我的问题是如何将选择内容设置为空,以使文本不再突出显示? code that Highlights the text after it is found:
找到文本后突出显示文本的代码:
IsTextSelected = true;
_body.Selection.Select(foundRange.Start, foundRange.End);
_body.SelectionBrush = selectionHighlighter;
newSearch = false;
Code when text is not found: 找不到文本时的代码:
MessageBox.Show("\'" + searchBox.Text.Trim() + "\' not found!");
newSearch = true;
lastOffset = -1;
IsTextSelected = false;
For a TextBox, set the SelectionLength property to zero. 对于文本框,将SelectionLength属性设置为零。
For a RichTextBox: 对于RichTextBox:
rtb.Selection.Select(rtb.Selection.Start, rtb.Selection.Start);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.