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

📄 insertform.cs

📁 学习正则表达式的编写
💻 CS
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Xml;

namespace RegexTool
{
	/// <summary>
	/// InsertForm 的摘要说明。
	/// </summary>
	public class InsertForm : System.Windows.Forms.Form
	{
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.Label label2;
		private System.Windows.Forms.TextBox txtRegex;
		private System.Windows.Forms.TextBox txtText;
		private System.Windows.Forms.Button button1;
		private System.Windows.Forms.Label label3;
		private System.Windows.Forms.TextBox txtDescription;
		/// <summary>
		/// 必需的设计器变量。
		/// </summary>
		private System.ComponentModel.Container components = null;

		

		public InsertForm()
		{
			//
			// Windows 窗体设计器支持所必需的
			//
			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()
		{
			System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(InsertForm));
			this.label1 = new System.Windows.Forms.Label();
			this.label2 = new System.Windows.Forms.Label();
			this.txtRegex = new System.Windows.Forms.TextBox();
			this.txtText = new System.Windows.Forms.TextBox();
			this.button1 = new System.Windows.Forms.Button();
			this.label3 = new System.Windows.Forms.Label();
			this.txtDescription = new System.Windows.Forms.TextBox();
			this.SuspendLayout();
			// 
			// label1
			// 
			this.label1.Location = new System.Drawing.Point(8, 44);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(80, 20);
			this.label1.TabIndex = 0;
			this.label1.Text = "正则表达式:";
			// 
			// label2
			// 
			this.label2.Location = new System.Drawing.Point(8, 68);
			this.label2.Name = "label2";
			this.label2.Size = new System.Drawing.Size(80, 23);
			this.label2.TabIndex = 1;
			this.label2.Text = "测试文本:";
			// 
			// txtRegex
			// 
			this.txtRegex.BackColor = System.Drawing.SystemColors.Control;
			this.txtRegex.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
			this.txtRegex.Location = new System.Drawing.Point(88, 40);
			this.txtRegex.Name = "txtRegex";
			this.txtRegex.Size = new System.Drawing.Size(256, 21);
			this.txtRegex.TabIndex = 2;
			this.txtRegex.Text = "";
			// 
			// txtText
			// 
			this.txtText.BackColor = System.Drawing.SystemColors.Control;
			this.txtText.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
			this.txtText.Location = new System.Drawing.Point(88, 68);
			this.txtText.Multiline = true;
			this.txtText.Name = "txtText";
			this.txtText.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
			this.txtText.Size = new System.Drawing.Size(260, 144);
			this.txtText.TabIndex = 3;
			this.txtText.Text = "";
			// 
			// button1
			// 
			this.button1.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
			this.button1.Location = new System.Drawing.Point(148, 220);
			this.button1.Name = "button1";
			this.button1.TabIndex = 4;
			this.button1.Text = "插入";
			this.button1.TextAlign = System.Drawing.ContentAlignment.TopCenter;
			this.button1.Click += new System.EventHandler(this.button1_Click);
			// 
			// label3
			// 
			this.label3.Location = new System.Drawing.Point(8, 16);
			this.label3.Name = "label3";
			this.label3.Size = new System.Drawing.Size(68, 20);
			this.label3.TabIndex = 5;
			this.label3.Text = "描述:";
			// 
			// txtDescription
			// 
			this.txtDescription.BackColor = System.Drawing.SystemColors.Control;
			this.txtDescription.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
			this.txtDescription.Location = new System.Drawing.Point(88, 12);
			this.txtDescription.Name = "txtDescription";
			this.txtDescription.Size = new System.Drawing.Size(256, 21);
			this.txtDescription.TabIndex = 6;
			this.txtDescription.Text = "";
			// 
			// InsertForm
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.ClientSize = new System.Drawing.Size(360, 245);
			this.Controls.Add(this.txtDescription);
			this.Controls.Add(this.label3);
			this.Controls.Add(this.button1);
			this.Controls.Add(this.txtText);
			this.Controls.Add(this.txtRegex);
			this.Controls.Add(this.label2);
			this.Controls.Add(this.label1);
			this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
			this.MaximizeBox = false;
			this.MinimizeBox = false;
			this.Name = "InsertForm";
			this.ShowInTaskbar = false;
			this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide;
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
			this.Text = "插入新正则表达式";
			this.ResumeLayout(false);

		}
		#endregion

		//插入新正则表达式事件
		private void button1_Click(object sender, System.EventArgs e)
		{
			try
			{
				if ( txtDescription.Text != "" && txtRegex.Text != "" && txtText.Text != "" )
				{
					//如果所有容都添完,则将所添内容写到数据文件内。
					string strDesc = @txtDescription.Text;
					string strRegex = @txtRegex.Text;
					string strText = @txtText.Text;
					//读取数据
					DataSet ds = new DataSet();
					ds.ReadXml("Data.xml");
					//新建一行,将新数据放入此行
					DataRow dr;
					string[] row = {strDesc, strRegex, strText };
					dr = ds.Tables[0].NewRow();
					dr.ItemArray = row;
					//添加进数据集并更新数据文件
					ds.Tables[0].Rows.Add(dr);
					ds.WriteXml("Data.xml");
				
					MessageBox.Show("添加成功!");
					this.Close();

				}
				else
				{
					MessageBox.Show("文本框内必须添内容!","错误!");
				}

			}
			catch ( Exception exep )
			{
				MessageBox.Show(exep.Message.ToString());
			}
		}
	}
}

⌨️ 快捷键说明

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