查找和替换.cs
上传用户:hueiseng
上传日期:2022-07-26
资源大小:156k
文件大小:4k
源码类别:

C#编程

开发平台:

Visual C++

  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Text;
  7. using System.Windows.Forms;
  8. namespace 笔记本
  9. {
  10.     public partial class 查找 : Form
  11.     {
  12.         static int findplace = 0;
  13.   
  14.         public 查找()
  15.         {
  16.             InitializeComponent();
  17.         }
  18.         public string note
  19.         {
  20.             get
  21.             {
  22.                 return textBox1.Text;
  23.             }
  24.         }
  25.         private void textBox1_TextChanged(object sender, EventArgs e)
  26.         {
  27.             if (textBox1.Text.Length > 0)
  28.                 button1.Enabled = true;
  29.             else
  30.                 button1.Enabled = false;
  31.         }
  32.         private void button1_Click(object sender, EventArgs e)
  33.         {
  34.             Form1 f1 = (Form1)this.Owner;
  35.             f1.Activate();
  36.             if (textBox1.Text.Length > 0)
  37.             {
  38.                 if (!checkBox1.Checked)
  39.                 {
  40.                     if (radioButton1.Checked)
  41.                     {
  42.                         findplace = f1.richTextBox1.SelectionStart - 1;
  43.                         if (findplace < 0)
  44.                         {
  45.                             MessageBox.Show("无法找到搜索项!");
  46.                             findplace = 0;
  47.                         }
  48.                         else
  49.                         {
  50.                             findplace = f1.richTextBox1.Text.LastIndexOf(textBox1.Text, findplace);
  51.                             f1.richTextBox1.Select(findplace, textBox1.Text.Length);
  52.                         }
  53.                     }
  54.                     if (radioButton2.Checked)
  55.                     {
  56.                         findplace = f1.richTextBox1.Text.IndexOf(textBox1.Text, findplace);
  57.                         if (findplace == -1)
  58.                         {
  59.                             MessageBox.Show("无法找到搜索项!");
  60.                             findplace = f1.richTextBox1.SelectionStart;
  61.                         }
  62.                         else
  63.                         {
  64.                             f1.richTextBox1.Select(findplace, textBox1.Text.Length);
  65.                             findplace = f1.richTextBox1.SelectionStart + textBox1.Text.Length;
  66.                         }
  67.                     }
  68.                 }
  69.                 else
  70.                 {
  71.                     if (radioButton1.Checked)
  72.                     {
  73.                         findplace = f1.richTextBox1.SelectionStart - 1;
  74.                         if (findplace < 0)
  75.                         {
  76.                             MessageBox.Show("无法找到搜索项!");
  77.                             findplace = 0;
  78.                         }
  79.                         else
  80.                         {
  81.                             findplace = f1.richTextBox1.Text.LastIndexOf(textBox1.Text, findplace, StringComparison.OrdinalIgnoreCase);
  82.                             f1.richTextBox1.Select(findplace, textBox1.Text.Length);
  83.                         }
  84.                     }
  85.                     if (radioButton2.Checked)
  86.                     {
  87.                         findplace = f1.richTextBox1.Text.IndexOf(textBox1.Text, findplace, StringComparison.OrdinalIgnoreCase);
  88.                         if (findplace == -1)
  89.                         {
  90.                             MessageBox.Show("无法找到搜索项!");
  91.                             findplace = f1.richTextBox1.SelectionStart;
  92.                         }
  93.                         else
  94.                         {
  95.                             f1.richTextBox1.Select(findplace, textBox1.Text.Length);
  96.                             findplace = f1.richTextBox1.SelectionStart + textBox1.Text.Length;
  97.                         }
  98.                     }
  99.                 }
  100.                 }
  101.             }
  102.         }
  103.     }