using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;

    namespace ArticleSearch
    {
        public partial class ArticleSearchUI : Form
        {
            public ArticleSearchUI()
            {
                InitializeComponent();
            }

            private int index = -1;
            private int totalCount = 0;
            private int searchPoint;
            private void searchButton_Click(object sender, EventArgs e)
            {
                string searchingWord = searchWordTextBox.Text;
                string article = articleRichTextBox.Text;
                double articleLength = article.Length;

                for(searchPoint=index+1;searchPoint<articleLength;searchPoint++)
                {
                   index = article.ToLower().IndexOf(searchingWord.ToLower(),searchPoint);
                    if(index>-1)
                            {
                            totalCount++;
                            articleRichTextBox.Select(index,searchingWord.Length);
                            articleRichTextBox.SelectionColor=Color.Magenta;
                            searchPoint = index + searchingWord.Length;
                            index = -1;
                            }
                    }
                    numberOfOccurenceLabel.Text = Convert.ToString(totalCount);
                    totalCount = 0;
              }
            }
        }
articleRichTextBox.SelectAll();
articleRichTextBox.SelectionBackColor = this.BackColor;
articleRichTextBox.DeselectAll();

Is how I've cleared selections in the past.

commented: I also try this logic.But its not work still.I think i am faching problem to put code at the right position of my program +0
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.