📄 form3.cs
字号:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace TextEditor
{
public partial class Form3 : Form
{
public RichTextBox s1;
public int start;
public Form3()
{
InitializeComponent();
}
private void Form3_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
string str1, str2;//存放要查找的文本和要替换的文本
str1 = textBox1.Text;//获取要查找的文本
str2 = textBox2.Text;//获取要替换的文本
if (start != -1)//如果找到
{
s1.SelectedText = str2;//替换
// i = i + 1;//计数器加1
// textBox4.Text = Convert.ToString(i);//显示替换次数
start = start + str2.Length;//下一次查找的起始位置
start = s1.Find(str1, start, RichTextBoxFinds.MatchCase);//查找下一个
}
else
{
MessageBox.Show("已替换到文档的结尾", "查找结束对话框");//显示查找结束对消息框
start = 0;//查找位置赋值为0,从头开始查找
//i = 0;//计数器赋值为0
}
s1.Focus();//为richTextBox1设置焦点
}
private void button2_Click(object sender, EventArgs e)
{
string str1, str2;//存放要查找的文本和要替换的文本
str1 = textBox1.Text;//获取要查找的文本
str2 = textBox2.Text;//获取要替换的文本
start = 0;
start = s1.Find(str1, start, RichTextBoxFinds.MatchCase);//查找下一个
while (start != -1)//如果找到
{
s1.SelectedText = str2;//替换
start = start + str2.Length;//下一次查找的起始位置
start = s1.Find(str1, start, RichTextBoxFinds.MatchCase);//查找下一个
}
MessageBox.Show("已替换到文档的结尾", "查找结束对话框");//显示查找结束对消息框
//textBox4.Text = Convert.ToString(i);
start = 0;//查找位置赋值为0,从头开始查找
s1.Focus();//为richTextBox1设置焦点
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -