C#RichTextBox 文本查找与替换

本文介绍了如何在C#中使用RichTextBox控件实现文本的查找、替换和全部替换功能。在操作期间,会禁用相关按钮并根据CheckBox的状态处理大小写敏感性。查找窗体的代码实现包括了向上查找以及区分大小写的全部替换策略。
摘要由CSDN通过智能技术生成

〖欢迎转载〗转载请注明出处

把 查找,替换,全部替换 三个button 的 Enabled 设置为 false ,f替换内容TextBox   Enabled 也设置为false , CheckBox2 为选中....


在主窗体中 关联一个函数就可以了,主窗体关联如下: Form_Mxdr.RichTextBox .Name=txtInput;

        /// <summary>获取 Form_Mxdr.RichTextBox<para> <para>
        /// 获取 RichTextBox 的读写操作权限</para></para> </summary>
        public RichTextBox RichTxtBox
        {
            get { return this.txtInput; }
            set { this.txtInput = value; }
        }


查找窗体代码: 向上查找无法区分大小写  ,全部替换只能替换查找内容限定区分出的大写或小写字母进行转换...


    public partial class formFind : Form
    {
        public formFind()
        {
            InitializeComponent();
        }


        private void formFind_Load(object sender, EventArgs e)
        {
            radioButton2.Checked = true;
        }


        #region ***********全局变量*************
        int start = 0;
        int sun = 0;
        int count = 0;
        #endregion


        #region =★*★*★=   四个 Button 点击事件   =★*★*★=
        private void button1_Click(object sender, EventArgs e)
        {
            Form_Mxdr f1 = (Form_Mxdr)this.Owner;
            RichTextBox rbox = f1.RichTxtBox;
            string str = this.textBox1.Text;
            if (this.checkBox1.Checked) //是否区分大小写
            {
                this.FindDownM(rbox, str);
            }
            else
            {
                if (this.radioButton2.Checked)
                {
                    this.FindDown(rbox, str);
                }
                else
                {
                    this.FindUp(rbox, str);
                }
            }
        }


        private void button2_Click(object sender, EventArgs e)
        {
            string str0=this.textBox
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值