Click here to Skip to main content
15,892,797 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Dear friends,

Good morning..

i am developing window application.in that i have richtextbox for getting paragraph content and another textbox for getting keyword content.based on the keyword i need to search in paragraph without considering the case.Because if the keyword is in title case it will not find the word in paragraph.


so can anyone solve my problem?

Thanks in advance
Posted

1 solution

Hi Jai

Below is a C# class file

C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace WindowsFormsApplication1
{
    class Class1
    {
        public static void HighlightText(System.Windows.Forms.RichTextBox myRtb, string word, System.Drawing.Color color)
        {
            int s_start = myRtb.SelectionStart, startIndex = 0, index = 0;

            System.Windows.Forms.RichTextBox myRtb1 = new System.Windows.Forms.RichTextBox();
            myRtb1.Text = myRtb.Text.ToLower();
            word = word.ToLower();

            while ((index = myRtb1.Text.IndexOf(word, startIndex)) != -1)
            {
                myRtb.Select(index, word.Length);
                myRtb.SelectionColor = color;

                startIndex = index + word.Length;
            }

            myRtb.SelectionStart = s_start;
            myRtb.SelectionLength = 0;
            myRtb.SelectionColor = System.Drawing.Color.Black;
        }
    }
}

C#



Call this function in your Search Button Click
Class1.HighlightText(richTextBox1, "wills", Color.Aqua);
<pre lang="c#">


Regards
Willington
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900