简体   繁体   English

突出显示文本后如何取消选择?

[英]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.

相关问题 MailItem 发送后如何访问它? - How can I access a MailItem after it has been sent? 如何取消选择 ListView 中的项目? - How can I unselect item in ListView? 如何在将文件保存到数据库后 60 秒后删除文件? - How can I delete a file/s after 60 seconds after it has been saved to the database? 列表框:一旦达到最大限制,如何取消选择/取消选择所选项目? - ListBox: How to deselect/unselect item selected once the maximum limit has been met? 在 FileSystemWatcher 中添加或删除新文件时,如何更改 ListView 中的文本颜色? - How can I change the text color in ListView when a new file has been added or deleted in FileSystemWatcher? 选中Tab后,如何将焦点放在textBox上? - How can I give focus to a textBox after a Tab has been selected? 我如何传递变量名称,而不是它的值。 然后在传递后使用它的值? - How can I pass a variables name, not its value. Then use its value after it has been passed? 如何在选择项目后使组合框保持打开状态? - How can I make a combobox stay open after an item has been selected? 如何在加载页面后加载此ASP.NET div? - How can I load this ASP.NET div after the page has been loaded? 选择选项卡后,如何将焦点放在任何控件上 - How can I give focus to any Control after a Tab has been selected
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM