⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 searchandreplaceform.cs

📁 在CSharpNotepad中可以创建和编辑简单文本文档
💻 CS
字号:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace CSharpNotepad
{
    public partial class searchAndreplaceForm : Form
    {
        private mainForm _Owner;    //标记该子窗口的父窗口

        private int strstart = 0;   //记录搜索点起始位置

        public searchAndreplaceForm()
        {
            InitializeComponent();
        }

        public searchAndreplaceForm(mainForm _Parent, string _SelectTabPage)
        {
            InitializeComponent();

            _Owner = _Parent;   //设置该子窗口的父窗口

            if (_SelectTabPage == "tabPageSearch")
            {
                tabControl1.SelectedTab = tabPageSearch;
                textBox1.Text = _Owner.currentForm.richTextBox1.SelectedText;
            }
            if (_SelectTabPage == "tabPageReplace")
            {
                tabControl1.SelectedTab = tabPageReplace;
                textBox2.Text = _Owner.currentForm.richTextBox1.SelectedText;
            }
        }
        
        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            if (textBox1.Text != "")
                searchButton1.Enabled = true;
            else
                searchButton1.Enabled = false;
        }

        private void searchButton1_Click(object sender, EventArgs e)
        {
            strstart += textBox1.Text.Length;

            if (checkBoxMatch1.Checked == false && checkBoxCaps1.Checked == false)
            {
                strstart = _Owner.currentForm.richTextBox1.Find(textBox1.Text, strstart, -1, System.Windows.Forms.RichTextBoxFinds.None);
            }
            else if (checkBoxMatch1.Checked == true && checkBoxCaps1.Checked == true)
            {
                strstart = _Owner.currentForm.richTextBox1.Find(textBox1.Text, strstart, -1, System.Windows.Forms.RichTextBoxFinds.WholeWord | System.Windows.Forms.RichTextBoxFinds.MatchCase);
            }
            else if (checkBoxMatch1.Checked == false && checkBoxCaps1.Checked == true)
            {
                strstart = _Owner.currentForm.richTextBox1.Find(textBox1.Text, strstart, -1, System.Windows.Forms.RichTextBoxFinds.WholeWord);
            }
            else if (checkBoxMatch1.Checked == true && checkBoxCaps1.Checked == false)
            {
                strstart = _Owner.currentForm.richTextBox1.Find(textBox1.Text, strstart, -1, System.Windows.Forms.RichTextBoxFinds.MatchCase);
            }

            if (strstart > 0)
            {
                _Owner.currentForm.richTextBox1.SelectionLength = textBox1.Text.Length;
                _Owner.currentForm.richTextBox1.SelectionStart = strstart;
                _Owner.currentForm.richTextBox1.Focus();
            }
            else
            {
                MessageBox.Show("已完成搜索文档,没有找到您要的内容。", "Notepad", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }

        private void cancelButton1_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void searchButton2_Click(object sender, EventArgs e)
        {
            strstart += textBox1.Text.Length;

            if (checkBoxMatch2.Checked == false && checkBoxCaps2.Checked == false)
            {
                strstart = _Owner.currentForm.richTextBox1.Find(textBox2.Text, strstart, -1, RichTextBoxFinds.None);
            }
            else if (checkBoxMatch2.Checked == true && checkBoxCaps2.Checked == true)
            {
                strstart = _Owner.currentForm.richTextBox1.Find(textBox2.Text, strstart, -1, RichTextBoxFinds.WholeWord | RichTextBoxFinds.MatchCase);
            }
            else if (checkBoxMatch2.Checked == false && checkBoxCaps2.Checked == true)
            {
                strstart = _Owner.currentForm.richTextBox1.Find(textBox2.Text, strstart, -1, RichTextBoxFinds.WholeWord);
            }
            else if (checkBoxMatch2.Checked == true && checkBoxCaps2.Checked == false)
            {
                strstart = _Owner.currentForm.richTextBox1.Find(textBox2.Text, strstart, -1, RichTextBoxFinds.MatchCase);
            }

            if (strstart > 0)
            {
                _Owner.currentForm.richTextBox1.SelectionLength = textBox2.Text.Length;
                _Owner.currentForm.richTextBox1.SelectionStart = strstart;
                _Owner.currentForm.richTextBox1.Focus();
            }
            else
            {
                MessageBox.Show("已完成搜索文档,没有找到您要的内容。", "Notepad", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }

        private void replaceButton_Click(object sender, EventArgs e)
        {
            strstart += textBox2.Text.Length;

            if (checkBoxMatch2.Checked == false && checkBoxCaps2.Checked == false)
            {
                strstart = _Owner.currentForm.richTextBox1.Find(textBox2.Text, strstart, -1, System.Windows.Forms.RichTextBoxFinds.None);
            }
            else if (checkBoxMatch2.Checked == true && checkBoxCaps2.Checked == true)
            {
                strstart = _Owner.currentForm.richTextBox1.Find(textBox2.Text, strstart, -1, System.Windows.Forms.RichTextBoxFinds.WholeWord | System.Windows.Forms.RichTextBoxFinds.MatchCase);
            }
            else if (checkBoxMatch2.Checked == false && checkBoxCaps2.Checked == true)
            {
                strstart = _Owner.currentForm.richTextBox1.Find(textBox2.Text, strstart, -1, System.Windows.Forms.RichTextBoxFinds.MatchCase);
            }
            else if (checkBoxMatch2.Checked == true && checkBoxCaps2.Checked == false)
            {
                strstart = _Owner.currentForm.richTextBox1.Find(textBox2.Text, strstart, -1, System.Windows.Forms.RichTextBoxFinds.WholeWord);
            }

            if (strstart > 0)
            {
                _Owner.currentForm.richTextBox1.SelectionLength = textBox2.Text.Length;
                _Owner.currentForm.richTextBox1.SelectionStart = strstart;
                _Owner.currentForm.richTextBox1.Focus();
                _Owner.currentForm.richTextBox1.SelectedText = textBox3.Text;
            }
            else
            {
                MessageBox.Show("已完成搜索文档,没有找到您要的内容。", "Notepad", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }

        private void cancelButton2_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void tabControl1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (textBox1.Text == "")
            {
                textBox1.Text = textBox2.Text;
            }
            if (textBox2.Text == "")
            {
                textBox2.Text = textBox1.Text;
            }
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -