基本信息
源码名称:RTF 格式文本的打开、显示、关键字搜索、替换、保存
源码大小:0.18M
文件格式:.rar
开发语言:C#
更新时间:2018-11-08
   友情提示:(无需注册或充值,赞助后即可获取资源下载链接)

     嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):78630559

本次赞助数额为: 2 元 
   源码介绍

使用C# 自带的控件实现 RTF 格式文本的打开、显示、关键字搜索、替换、保存,适合C#初学对控件、字符串操作的理解

private void BtnReplace_Click(object sender, EventArgs e)
        {
            Regex regex = new Regex(txtKeyWords.Text);
            Match match = regex.Match(rtxtbox.Text);
            while (match.Success)
            {
                regex.Replace(txtKeyWords.Text, txtReplaceWord.Text);
                match = regex.Match(txtReplaceWord.Text, match.Index   txtReplaceWord.TextLength);
            }
        }

        private void BtnSearch_Click(object sender, EventArgs e)
        {
            string strKeyWords = txtKeyWords.Text.Trim();
           
            Regex regex = new Regex(strKeyWords);
            Match match = regex.Match(rtxtbox.Text);
            while (match.Success)
            {
                rtxtbox.Select(match.Index, strKeyWords.Length);
                rtxtbox.SelectionColor = Color.Red;
                match = regex.Match(rtxtbox.Text, match.Index   strKeyWords.Length);
            }
        }

        private void PasteToolStripMenuItem_Click(object sender, EventArgs e)
        {
            rtxtbox.AppendText(Clipboard.GetText());
        }

        private void CopyToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Clipboard.SetDataObject(rtxtbox.SelectedText, false);

        }

        private void CutToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //Clipboard.SetDataObject(rtxtbox.SelectedText, false);
            rtxtbox.Cut();
        }

        private void Rtxtbox_TextChanged(object sender, EventArgs e)
        {
            if (getRichTextBoxState())
                btnCleanBox.Enabled = true;
            else
                btnCleanBox.Enabled = false;
        }

        private void Form1_Load(object sender, EventArgs e)
        {
                btnCleanBox.Enabled = false;
        }

        private void BtnExit_Click(object sender, EventArgs e)
        {
            this.Close();
            Application.Exit();
        }

        private void BtnCleanBox_Click(object sender, EventArgs e)
        {
            rtxtbox.Clear();
            rtxtbox.Focus();
        }

        private void BtnSaveFile_Click(object sender, EventArgs e)
        {
            if (rtxtbox.TextLength > 0)
            {
                if (saveFileDialog1.ShowDialog() == DialogResult.OK)
                {
                    saveFileDialog1.Filter = "RTF 文件(*.RTF)|*.RTF|ini文件(*.ini)|*.ini|word 文件(*.doc)|*.doc";
                    rtxtbox.SaveFile(saveFileDialog1.FileName ".RTF", RichTextBoxStreamType.RichNoOleObjs);
                    rtxtbox.Clear();
                    MessageBox.Show("文件保存成功!");
                }
            }
        }

        private void BtnOpenFile_Click(object sender, EventArgs e)
        {
            openFileDialog1.Filter = "RTF 文件(*.RTF)|*.RTF|ini文件(*.ini)|*.ini|word 文件(*.doc)|*.doc";
            if (openFileDialog1.ShowDialog() == DialogResult.OK || openFileDialog1.FileName.Length > 0)
            {
                rtxtbox.LoadFile(openFileDialog1.FileName, RichTextBoxStreamType.RichText);
            }
        }