-
大小: 18KB文件類型: .rar金幣: 2下載: 0 次發布日期: 2021-05-25
- 語言: C#
- 標簽: C#??RichTextBox??查找??替換??
資源簡介
很多網友在利用RichTextBox控件作文本編輯器時,都反映不知道怎么做查找和替換,我在這里給實現一下,共享給大家吧
附件便是一個僅僅實現了查找和替換功能的文本編輯器,該功能已經完善了

代碼片段和文件信息
using?System;
using?System.Collections.Generic;
using?System.ComponentModel;
using?System.Data;
using?System.Drawing;
using?System.Text;
using?System.Windows.Forms;
namespace?MyNote
{
????public?partial?class?FindReplaceForm?:?Form
????{
????????private?INoteTextBox?m_noteTextBox?=?null;
????????public?INoteTextBox?NoteTextBox
????????{
????????????get?{?return?this.m_noteTextBox;?}
????????????set?{?this.m_noteTextBox?=?value;?}
????????}
????????internal?Control?TextBoxControl
????????{
????????????get?{?return?this.m_noteTextBox?as?Control;?}
????????}
????????public?FindReplaceForm()
????????{
????????????this.InitializeComponent();
????????}
????????private?void?SetButtonState()
????????{
????????????this.btnFindNext.Enabled?=?false;
????????????this.btnReplace.Enabled?=?false;
????????????this.btnReplaceAll.Enabled?=?false;
????????????if?(this.txtFindText.Text.Equals(string.Empty))
????????????????return;
????????????this.btnFindNext.Enabled?=?true;
????????????if?(string.Compare(this.txtFindText.Text?this.txtReplaceText.Text?!this.chkMatchCase.Checked)?==?0)
????????????????return;
????????????this.btnReplace.Enabled?=?true;
????????????this.btnReplaceAll.Enabled?=?true;
????????}
????????private?void?txtFindText_TextChanged(object?sender?EventArgs?e)
????????{
????????????this.SetButtonState();
????????}
????????private?void?txtReplaceText_TextChanged(object?sender?EventArgs?e)
????????{
????????????this.SetButtonState();
????????}
????????private?void?chkMatchCase_CheckedChanged(object?sender?EventArgs?e)
????????{
????????????this.SetButtonState();
????????}
????????private?void?btnFindNext_Click(object?sender?EventArgs?e)
????????{
????????????if?(this.TextBoxControl?==?null?||?this.TextBoxControl.IsDisposed)
????????????????return;
????????????while?(true)
????????????{
????????????????int?result?=?this.m_noteTextBox.FindNext(
????????????????????this.txtFindText.Text
????????????????????this.chkMatchCase.Checked
????????????????????this.chkReverseFind.Checked
????????????????);
????????????????if?(result?>=?0)
????????????????????break;
????????????????string?szMsgInfo?=?null;
????????????????if?(this.chkReverseFind.Checked)
????????????????????szMsgInfo?=?“已經查找到文檔開始!是否重新從文檔末尾處查找?“;
????????????????else
????????????????????szMsgInfo?=?“已經查找到文檔結尾!是否重新從文檔開始處查找?“;
????????????????DialogResult?dlgResult?=?MessageBox.Show(szMsgInfo?“查找和替換“?MessageBoxButtons.YesNo?MessageBoxIcon.Question);
????????????????if?(dlgResult?!=?DialogResult.Yes)
????????????????????break;
????????????????if?(this.chkReverseFind.Checked)
????????????????????this.m_noteTextBox.Selectionstart?=?this.m_noteTextBox.TextLength;
????????????????else
????????????????????this.m_noteTextBox.Selectionstart?=?0;
????????????}
????????}
????????private?void?btnReplace_Click(object?sender?EventArgs?e)
????????{
????????????if?(this.TextBoxControl?==?null?||?this
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????4861??2008-12-21?23:37??MyNote\FindReplaceForm.cs
?????文件???????7589??2008-12-21?23:37??MyNote\FindReplaceForm.Designer.cs
?????文件???????5814??2008-12-21?23:37??MyNote\FindReplaceForm.resx
?????文件????????723??2008-12-21?23:04??MyNote\MainForm.cs
?????文件???????4259??2008-12-21?23:04??MyNote\MainForm.Designer.cs
?????文件???????6012??2008-12-21?23:04??MyNote\MainForm.resx
?????文件???????3715??2008-12-21?21:40??MyNote\MyNote.csproj
?????文件???????2872??2008-12-21?23:34??MyNote\NoteTextBox.cs
?????文件????????476??2008-12-21?15:20??MyNote\Program.cs
?????文件???????1266??2008-12-21?15:17??MyNote\Properties\AssemblyInfo.cs
?????文件???????2839??2008-12-21?15:17??MyNote\Properties\Resources.Designer.cs
?????文件???????5612??2008-12-21?15:17??MyNote\Properties\Resources.resx
?????文件???????1089??2008-12-21?15:17??MyNote\Properties\Settings.Designer.cs
?????文件????????249??2008-12-21?15:17??MyNote\Properties\Settings.settings
?????文件????????907??2008-12-21?15:17??MyNote.sln
????..A..H.?????26624??2008-12-21?23:39??MyNote.suo
?????目錄??????????0??2008-12-21?15:17??MyNote\Properties
?????目錄??????????0??2008-12-21?23:39??MyNote
-----------?---------??----------?-----??----
????????????????74907????????????????????18
- 上一篇:C# 保存和讀取xm
l配置文件 - 下一篇:C#開發的類似PHOTOSHOP的軟件
評論
共有 條評論