替换.cs
资源名称:Notebook.rar [点击查看]
上传用户:hueiseng
上传日期:2022-07-26
资源大小:156k
文件大小:4k
源码类别:
C#编程
开发平台:
Visual C++
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Text;
- using System.Windows.Forms;
- namespace 笔记本
- {
- public partial class 替换 : Form
- {
- int findplace = 0;
- public 替换()
- {
- InitializeComponent();
- }
- private void button1_Click(object sender, EventArgs e)
- {
- Form1 f1 = (Form1)this.Owner;
- f1.Activate();
- if (textBox1.Text.Length > 0)
- {
- if (!checkBox1.Checked)
- {
- findplace = f1.richTextBox1.Text.IndexOf(textBox1.Text, findplace);
- if (findplace == -1)
- {
- MessageBox.Show("无法找到搜索项!");
- findplace = f1.richTextBox1.SelectionStart;
- }
- else
- {
- f1.richTextBox1.Select(findplace, textBox1.Text.Length);
- findplace = f1.richTextBox1.SelectionStart + textBox1.Text.Length;
- }
- }
- else
- {
- findplace = f1.richTextBox1.Text.IndexOf(textBox1.Text, findplace, StringComparison.OrdinalIgnoreCase);
- if (findplace == -1)
- {
- MessageBox.Show("无法找到搜索项!");
- findplace = f1.richTextBox1.SelectionStart;
- }
- else
- {
- f1.richTextBox1.Select(findplace, textBox1.Text.Length);
- findplace = f1.richTextBox1.SelectionStart + textBox1.Text.Length;
- }
- }
- }
- }
- private void button2_Click(object sender, EventArgs e)
- {
- Form1 f1 = (Form1)this.Owner;
- f1.Activate();
- if (textBox1.Text.Length != 0&&textBox2.Text.Length != 0)
- {
- f1.richTextBox1.SelectedText = f1.richTextBox1.SelectedText.Replace( f1.richTextBox1.SelectedText, textBox2.Text);
- }
- else
- MessageBox.Show("please fill the text.");
- }
- private void button3_Click(object sender, EventArgs e)
- {
- Form1 f1 = (Form1)this.Owner;
- f1.Activate();
- if (!checkBox1.Checked)
- {
- if (textBox1.Text.Length != 0 && textBox2.Text.Length != 0)
- {
- f1.richTextBox1.Text = f1.richTextBox1.Text.Replace(textBox1.Text, textBox2.Text);
- }
- else
- MessageBox.Show("please fill the text.");
- }
- else
- {
- findplace = 0;
- while (findplace >= 0)
- {
- findplace = f1.richTextBox1.Text.IndexOf(textBox1.Text, findplace, StringComparison.OrdinalIgnoreCase);
- if (findplace == -1)
- return;
- f1.richTextBox1.Select(findplace, textBox1.Text.Length);
- if (textBox1.Text.Length != 0 && textBox2.Text.Length != 0)
- f1.richTextBox1.SelectedText = f1.richTextBox1.SelectedText.Replace(f1.richTextBox1.SelectedText, textBox2.Text);
- else
- {
- MessageBox.Show("please fill the text.");
- return;
- }
- }
- ;
- }
- }
- }
- }