title: Deselect text in RichTextBox
body: <p>I have a <code>RichTextBox</code> with a search box under it. I use the following code for the search functionality:</p>
  
  <pre><code>TabPage activePage = tabs.SelectedTab;
              RichTextBox xmlBox = activePage.Controls.Find("xmlBox", true).Single() as RichTextBox;
  
  xmlBox.DeselectAll();
  
  int index = 0;
  int len = xmlBox.TextLength;
  int lastIndex = xmlBox.Text.LastIndexOf(tbSearch.Text);
  
  while (index &lt; lastIndex)
  {
       xmlBox.Find(tbSearch.Text, index, len, RichTextBoxFinds.WholeWord);
       xmlBox.SelectionBackColor = Color.Yellow;
       index = xmlBox.Text.IndexOf(tbSearch.Text, index) + 1;
  }
  </code></pre>
  
  <p>What I want is that lets say a user types the word <code>User</code>. When he types the <code>U</code> I want all the <code>U</code>s to be highlighted, etc. and then if he deletes the <code>r</code> I want only <code>Use</code> to be highlighted. I was thinking that <code>DeselectAll()</code> would do the trick, but this isn`t working. Any other way to do this?</p>