title: Searching string in richtextbox
body: <p>This is my code on finding text in my richtextbox and highlighting it: </p>
  
  <pre><code>        int start = 0;
          int indexOfSearchText = 0;
  
          private void button1_Click(object sender, EventArgs e)
          {
              int startindex = 0;
  
              if (textBox1.Text.Length &gt; 0)
                  startindex = FindMyText(textBox1.Text.Trim(), start, richTextBox1.Text.Length);
  
              // If string was found in the RichTextBox, highlight it
              if (startindex &gt;= 0)
              {
                  // Set the highlight color as red
                  richTextBox1.SelectionBackColor = Color.Red;
                  // Find the end index. End Index = number of characters in textbox
                  int endindex = textBox1.Text.Length;
                  // Highlight the search string
                  richTextBox1.Select(startindex, endindex);
                  richTextBox1.ScrollToCaret();
                  // mark the start position after the position of
                  // last search string
                  start = startindex + endindex;
              }
  
              else
              {
                  MessageBox.Show("0 occurence in richtextbox");
              }
          }
  
          public int FindMyText(string txtToSearch, int searchStart, int searchEnd)
          {
              // Unselect the previously searched string
              if (searchStart &gt; 0 &amp;&amp; searchEnd &gt; 0 &amp;&amp; indexOfSearchText &gt;= 0)
              {
                  richTextBox1.Undo();
              }
  
              // Set the return value to -1 by default.
              int retVal = -1;
  
              // A valid starting index should be specified.
              // if indexOfSearchText = -1, the end of search
              if (searchStart &gt;= 0 &amp;&amp; indexOfSearchText &gt;= 0)
              {
                  // A valid ending index
                  if (searchEnd &gt; searchStart || searchEnd == -1)
                  {
                      // Find the position of search string in RichTextBox
                      indexOfSearchText = richTextBox1.Find(txtToSearch, searchStart, searchEnd, RichTextBoxFinds.None);
                      // Determine whether the text was found in richTextBox1.
                      if (indexOfSearchText != -1)
                      {
                          // Return the index to the specified search text.
                          retVal = indexOfSearchText;
                      }
                  }
              }
              return retVal;
          }
  
          private void textBox1_TextChanged(object sender, EventArgs e)
          {
              start = 0;
              indexOfSearchText = 0;
          }
      }
  }
  </code></pre>
  
  <p>The problem is, when it reaches the end of the richtextBox1, it did not restart at the beginning again! I want to loop it again to the start after reaching the end of the richtextBox1.text. </p>