在富文本框中查找功能而不考虑大小写 [英] Find function in rich text box without consider case

查看:70
本文介绍了在富文本框中查找功能而不考虑大小写的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的朋友们,



早上好..



i正在开发窗口应用程序。在那我有获取段落内容的richtextbox和获取关键字内容的另一个文本框。基于关键字我需要在段落中搜索而不考虑大小写。因为如果关键字在标题中,它将不会在段落中找到该单词。





所以有人能解决我的问题吗?



提前致谢

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

推荐答案

你好



下面是一个C#类文件



Hi Jai

Below is a C# class file

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;
        }
    }
}









在搜索按钮中调用此函数点击



Call this function in your Search Button Click

Class1.HighlightText(richTextBox1, "wills", Color.Aqua);

<pre lang="c#">





问候

Willington



Regards
Willington


这篇关于在富文本框中查找功能而不考虑大小写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆