SEARCH C# PROGRAMMING CODES HERE

How to Search & Highlight text in C# Visual studio.

Search & Highlight text in C#
1-To search and Highlight text I am using Richtextbox, Textbox, and Button from the toolbox.
2-copy & paste this code to button1_click event.

private void button1_Click(object sender, EventArgs e)

        {
            int index = 0;
            string txt = richTextBox1.Text;
            richTextBox1.Text = "";
            richTextBox1.Text = txt;
            while (index < richTextBox1.Text.LastIndexOf(textBox1.Text))
            {
                richTextBox1.Find(textBox1.Text, index, richTextBox1.TextLength, RichTextBoxFinds.None);
                richTextBox1.SelectionBackColor = Color.Yellow;
                index = richTextBox1.Text.IndexOf(textBox1.Text, index) + 1;
            }

        }



No comments:

Post a Comment