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

📄 find.cs

📁 “记事本”是一个用来创建简单的文档的基本的文本编辑器。“记事本”最常用来查看或编辑文本 (.txt) 文件
💻 CS
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;

namespace jsb
{
	/// <summary>
	/// Form3 的摘要说明。
	/// </summary>
	public class Form3 : System.Windows.Forms.Form
	{
		private Form1 f1;
		private int i = 0;
		private int j = 0;
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.TextBox textBox1;
		private System.Windows.Forms.Button button1;
		private System.Windows.Forms.Button button2;
		private System.Windows.Forms.GroupBox groupBox1;
		private System.Windows.Forms.CheckBox checkBox1;
		private System.Windows.Forms.RadioButton radio2;
		private System.Windows.Forms.RadioButton radio1;
		/// <summary>
		/// 必需的设计器变量。
		/// </summary>
		private System.ComponentModel.Container components = null;

		public Form3(Form1 f1)
		{
			//
			// Windows 窗体设计器支持所必需的
			//
			this.f1 = f1;
			InitializeComponent();

			//
			// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
			//
		}

		/// <summary>
		/// 清理所有正在使用的资源。
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows 窗体设计器生成的代码
		/// <summary>
		/// 设计器支持所需的方法 - 不要使用代码编辑器修改
		/// 此方法的内容。
		/// </summary>
		private void InitializeComponent()
		{
			this.label1 = new System.Windows.Forms.Label();
			this.textBox1 = new System.Windows.Forms.TextBox();
			this.button1 = new System.Windows.Forms.Button();
			this.button2 = new System.Windows.Forms.Button();
			this.groupBox1 = new System.Windows.Forms.GroupBox();
			this.radio2 = new System.Windows.Forms.RadioButton();
			this.radio1 = new System.Windows.Forms.RadioButton();
			this.checkBox1 = new System.Windows.Forms.CheckBox();
			this.groupBox1.SuspendLayout();
			this.SuspendLayout();
			// 
			// label1
			// 
			this.label1.AutoSize = true;
			this.label1.Location = new System.Drawing.Point(16, 20);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(66, 17);
			this.label1.TabIndex = 0;
			this.label1.Text = "查找内容:";
			// 
			// textBox1
			// 
			this.textBox1.Location = new System.Drawing.Point(96, 16);
			this.textBox1.Name = "textBox1";
			this.textBox1.Size = new System.Drawing.Size(192, 21);
			this.textBox1.TabIndex = 1;
			this.textBox1.Text = "";
			this.textBox1.TextChanged += new System.EventHandler(this.textBox1_TextChanged);
			// 
			// button1
			// 
			this.button1.Enabled = false;
			this.button1.Location = new System.Drawing.Point(304, 16);
			this.button1.Name = "button1";
			this.button1.TabIndex = 2;
			this.button1.Text = "查找下一个";
			this.button1.Click += new System.EventHandler(this.button1_Click);
			// 
			// button2
			// 
			this.button2.Location = new System.Drawing.Point(304, 56);
			this.button2.Name = "button2";
			this.button2.TabIndex = 3;
			this.button2.Text = "取  消";
			this.button2.Click += new System.EventHandler(this.button2_Click);
			// 
			// groupBox1
			// 
			this.groupBox1.Controls.Add(this.radio2);
			this.groupBox1.Controls.Add(this.radio1);
			this.groupBox1.Location = new System.Drawing.Point(112, 56);
			this.groupBox1.Name = "groupBox1";
			this.groupBox1.Size = new System.Drawing.Size(168, 48);
			this.groupBox1.TabIndex = 4;
			this.groupBox1.TabStop = false;
			this.groupBox1.Text = "方向";
			// 
			// radio2
			// 
			this.radio2.Checked = true;
			this.radio2.Location = new System.Drawing.Point(104, 16);
			this.radio2.Name = "radio2";
			this.radio2.Size = new System.Drawing.Size(48, 24);
			this.radio2.TabIndex = 1;
			this.radio2.TabStop = true;
			this.radio2.Text = "向下";
			this.radio2.CheckedChanged += new System.EventHandler(this.radio2_CheckedChanged);
			// 
			// radio1
			// 
			this.radio1.Location = new System.Drawing.Point(24, 17);
			this.radio1.Name = "radio1";
			this.radio1.Size = new System.Drawing.Size(53, 24);
			this.radio1.TabIndex = 0;
			this.radio1.Text = "向上";
			this.radio1.CheckedChanged += new System.EventHandler(this.radio1_CheckedChanged);
			// 
			// checkBox1
			// 
			this.checkBox1.Location = new System.Drawing.Point(16, 72);
			this.checkBox1.Name = "checkBox1";
			this.checkBox1.Size = new System.Drawing.Size(88, 24);
			this.checkBox1.TabIndex = 5;
			this.checkBox1.Text = "区分大小写";
			// 
			// Form3
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.ClientSize = new System.Drawing.Size(394, 114);
			this.Controls.Add(this.checkBox1);
			this.Controls.Add(this.groupBox1);
			this.Controls.Add(this.button2);
			this.Controls.Add(this.button1);
			this.Controls.Add(this.textBox1);
			this.Controls.Add(this.label1);
			this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;
			this.Name = "Form3";
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
			this.Text = "查找";
			this.TopMost = true;
			this.Load += new System.EventHandler(this.Form3_Load);
			this.groupBox1.ResumeLayout(false);
			this.ResumeLayout(false);

		}
		#endregion
		
		private void textBox1_TextChanged(object sender, System.EventArgs e)
		{
			this.button1.Enabled = true;
		}

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

		private void Form3_Load(object sender, System.EventArgs e)
		{
			j =f1.richText.TextLength;
		}

		private void button1_Click(object sender, System.EventArgs e)
		{
			if (checkBox1.Checked == true)
			{
				RichTextBoxFinds rbf = RichTextBoxFinds.MatchCase;
				f1.richText.Focus();
				i=f1.richText.Find(textBox1.Text,i,f1.richText.TextLength,rbf);
				if (i < 0)
				{
					this.TopMost = false;
					MessageBox.Show("文本以全部搜索完毕","提示!",MessageBoxButtons.OK,MessageBoxIcon.Exclamation);
					this.TopMost = true;
				}
				i = i+1;
				return;
			}
			if (radio1.Checked == true)
			{
				if (j<=0)
				{
					j = f1.richText.TextLength;
				}
				RichTextBoxFinds rbf = RichTextBoxFinds.Reverse;
				j=f1.richText.Find(textBox1.Text,i,j,rbf);
				f1.richText.Focus();
				if (j <= 0)
				{
					this.TopMost = false;
					MessageBox.Show("文本以全部搜索完毕","提示!",MessageBoxButtons.OK,MessageBoxIcon.Exclamation);
					this.TopMost = true;
					f1.richText.Focus();
				}
			}
			if (radio2.Checked == true)
			{
				f1.richText.Focus();
				i=f1.richText.Find(textBox1.Text,i,f1.richText.TextLength,RichTextBoxFinds.None);
				if (i < 0)
				{		
					this.TopMost = false;
					MessageBox.Show("文本以全部搜索完毕","提示!",MessageBoxButtons.OK,MessageBoxIcon.Exclamation);
					this.TopMost = true;
					f1.richText.Focus();
				}
				i = i+1;
			}
		}

		private void radio2_CheckedChanged(object sender, System.EventArgs e)
		{
			this.checkBox1.Enabled = true;
		}

		private void radio1_CheckedChanged(object sender, System.EventArgs e)
		{
			this.checkBox1.Checked = false;
			this.checkBox1.Enabled = false;
		}

	}
}

⌨️ 快捷键说明

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