Form1.cs
资源名称:Visual.rar [点击查看]
上传用户:yiyuerguo
上传日期:2014-09-27
资源大小:3781k
文件大小:8k
源码类别:
C#编程
开发平台:
Others
- using System;
- using System.Drawing;
- using System.Collections;
- using System.ComponentModel;
- using System.Windows.Forms;
- using System.Data;
- using System.Text.RegularExpressions;
- namespace RegexT
- {
- /// <summary>
- /// Form1 的摘要说明。
- /// </summary>
- public class Form1 : System.Windows.Forms.Form
- {
- private System.Windows.Forms.GroupBox groupBox1;
- private System.Windows.Forms.TextBox textBox1;
- private System.Windows.Forms.TextBox textBox2;
- private System.Windows.Forms.TextBox textBox3;
- private System.Windows.Forms.Label label1;
- private System.Windows.Forms.Label label2;
- private System.Windows.Forms.Button button1;
- private System.Windows.Forms.Button button2;
- private System.Windows.Forms.CheckBox IgnoreCaseChkBox;
- private System.Windows.Forms.CheckBox SingleLineChkBox;
- private System.Windows.Forms.CheckBox IgnorePatternWhitespaceChkBox;
- private System.Windows.Forms.CheckBox RightToLeftChkBox;
- private System.Windows.Forms.CheckBox MultiLineChkBox;
- /// <summary>
- /// 必需的设计器变量。
- /// </summary>
- private System.ComponentModel.Container components = null;
- public Form1()
- {
- //
- // Windows 窗体设计器支持所必需的
- //
- InitializeComponent();
- //
- // TODO: 在 InitializeComponent 调用后添加任何构造函数代码
- //
- }
- /// <summary>
- /// 清理所有正在使用的资源。
- /// </summary>
- protected override void Dispose( bool disposing )
- {
- if( disposing )
- {
- if (components != null)
- {
- components.Dispose();
- }
- }
- base.Dispose( disposing );
- }
- private RegexOptions GetSel()
- {
- RegexOptions sel = RegexOptions.None;
- if(this.IgnoreCaseChkBox.Checked)
- sel |= RegexOptions.IgnoreCase;
- if(this.IgnorePatternWhitespaceChkBox.Checked)
- sel |= RegexOptions.IgnorePatternWhitespace;
- if(this.MultiLineChkBox.Checked)
- sel |= RegexOptions.Multiline;
- if(this.SingleLineChkBox.Checked)
- sel |= RegexOptions.Singleline;
- if(this.RightToLeftChkBox.Checked)
- sel |= RegexOptions.RightToLeft;
- return sel;
- }
- #region Windows 窗体设计器生成的代码
- /// <summary>
- /// 设计器支持所需的方法 - 不要使用代码编辑器修改
- /// 此方法的内容。
- /// </summary>
- private void InitializeComponent()
- {
- this.groupBox1 = new System.Windows.Forms.GroupBox();
- this.IgnoreCaseChkBox = new System.Windows.Forms.CheckBox();
- this.SingleLineChkBox = new System.Windows.Forms.CheckBox();
- this.IgnorePatternWhitespaceChkBox = new System.Windows.Forms.CheckBox();
- this.RightToLeftChkBox = new System.Windows.Forms.CheckBox();
- this.MultiLineChkBox = new System.Windows.Forms.CheckBox();
- this.textBox1 = new System.Windows.Forms.TextBox();
- this.textBox2 = new System.Windows.Forms.TextBox();
- this.textBox3 = new System.Windows.Forms.TextBox();
- this.label1 = new System.Windows.Forms.Label();
- this.label2 = new System.Windows.Forms.Label();
- this.button1 = new System.Windows.Forms.Button();
- this.button2 = new System.Windows.Forms.Button();
- this.groupBox1.SuspendLayout();
- this.SuspendLayout();
- //
- // groupBox1
- //
- this.groupBox1.Controls.Add(this.MultiLineChkBox);
- this.groupBox1.Controls.Add(this.RightToLeftChkBox);
- this.groupBox1.Controls.Add(this.IgnorePatternWhitespaceChkBox);
- this.groupBox1.Controls.Add(this.SingleLineChkBox);
- this.groupBox1.Controls.Add(this.IgnoreCaseChkBox);
- this.groupBox1.Location = new System.Drawing.Point(8, 96);
- this.groupBox1.Name = "groupBox1";
- this.groupBox1.Size = new System.Drawing.Size(368, 112);
- this.groupBox1.TabIndex = 0;
- this.groupBox1.TabStop = false;
- this.groupBox1.Text = "选项";
- //
- // IgnoreCaseChkBox
- //
- this.IgnoreCaseChkBox.Location = new System.Drawing.Point(8, 16);
- this.IgnoreCaseChkBox.Name = "IgnoreCaseChkBox";
- this.IgnoreCaseChkBox.TabIndex = 0;
- this.IgnoreCaseChkBox.Text = "忽略大小写";
- //
- // SingleLineChkBox
- //
- this.SingleLineChkBox.Location = new System.Drawing.Point(128, 16);
- this.SingleLineChkBox.Name = "SingleLineChkBox";
- this.SingleLineChkBox.TabIndex = 1;
- this.SingleLineChkBox.Text = "单行模式";
- //
- // IgnorePatternWhitespaceChkBox
- //
- this.IgnorePatternWhitespaceChkBox.Location = new System.Drawing.Point(8, 48);
- this.IgnorePatternWhitespaceChkBox.Name = "IgnorePatternWhitespaceChkBox";
- this.IgnorePatternWhitespaceChkBox.Size = new System.Drawing.Size(168, 24);
- this.IgnorePatternWhitespaceChkBox.TabIndex = 2;
- this.IgnorePatternWhitespaceChkBox.Text = "消除模式空白处理";
- //
- // RightToLeftChkBox
- //
- this.RightToLeftChkBox.Location = new System.Drawing.Point(224, 48);
- this.RightToLeftChkBox.Name = "RightToLeftChkBox";
- this.RightToLeftChkBox.TabIndex = 3;
- this.RightToLeftChkBox.Text = "右至左";
- //
- // MultiLineChkBox
- //
- this.MultiLineChkBox.Location = new System.Drawing.Point(224, 16);
- this.MultiLineChkBox.Name = "MultiLineChkBox";
- this.MultiLineChkBox.TabIndex = 4;
- this.MultiLineChkBox.Text = "多行模式";
- //
- // textBox1
- //
- this.textBox1.Location = new System.Drawing.Point(8, 32);
- this.textBox1.Multiline = true;
- this.textBox1.Name = "textBox1";
- this.textBox1.Size = new System.Drawing.Size(368, 56);
- this.textBox1.TabIndex = 1;
- this.textBox1.Text = "";
- //
- // textBox2
- //
- this.textBox2.Location = new System.Drawing.Point(8, 248);
- this.textBox2.Multiline = true;
- this.textBox2.Name = "textBox2";
- this.textBox2.Size = new System.Drawing.Size(368, 72);
- this.textBox2.TabIndex = 2;
- this.textBox2.Text = "";
- //
- // textBox3
- //
- this.textBox3.Location = new System.Drawing.Point(8, 328);
- this.textBox3.Name = "textBox3";
- this.textBox3.TabIndex = 3;
- this.textBox3.Text = "";
- //
- // label1
- //
- this.label1.Location = new System.Drawing.Point(8, 8);
- this.label1.Name = "label1";
- this.label1.Size = new System.Drawing.Size(100, 16);
- this.label1.TabIndex = 4;
- this.label1.Text = "标准式";
- //
- // label2
- //
- this.label2.Location = new System.Drawing.Point(8, 216);
- this.label2.Name = "label2";
- this.label2.TabIndex = 5;
- this.label2.Text = "应用检测试";
- //
- // button1
- //
- this.button1.Location = new System.Drawing.Point(136, 328);
- this.button1.Name = "button1";
- this.button1.Size = new System.Drawing.Size(112, 23);
- this.button1.TabIndex = 6;
- this.button1.Text = "验证";
- this.button1.Click += new System.EventHandler(this.button1_Click);
- //
- // button2
- //
- this.button2.Location = new System.Drawing.Point(272, 328);
- this.button2.Name = "button2";
- this.button2.Size = new System.Drawing.Size(104, 23);
- this.button2.TabIndex = 7;
- this.button2.Text = "清空";
- this.button2.Click += new System.EventHandler(this.button2_Click);
- //
- // Form1
- //
- this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
- this.ClientSize = new System.Drawing.Size(384, 381);
- this.Controls.Add(this.button2);
- this.Controls.Add(this.button1);
- this.Controls.Add(this.label2);
- this.Controls.Add(this.label1);
- this.Controls.Add(this.textBox3);
- this.Controls.Add(this.textBox2);
- this.Controls.Add(this.textBox1);
- this.Controls.Add(this.groupBox1);
- this.Name = "Form1";
- this.Text = "Form1";
- this.groupBox1.ResumeLayout(false);
- this.ResumeLayout(false);
- }
- #endregion
- /// <summary>
- /// 应用程序的主入口点。
- /// </summary>
- [STAThread]
- static void Main()
- {
- Application.Run(new Form1());
- }
- private void button1_Click(object sender, System.EventArgs e)
- {
- try
- {
- RegexOptions sel = this.GetSel();
- Regex RegexT = new Regex(textBox1.Text,sel);
- if(RegexT.IsMatch(textBox2.Text))
- {
- textBox3.ForeColor = Color.Black;
- textBox3.Text = "正则表达式匹配";
- }
- else
- {
- textBox3.ForeColor = Color.Red;
- textBox3.Text = "正则表达式不匹配";
- }
- }
- catch(ArgumentException ax)
- {
- textBox3.ForeColor = Color.Red;
- textBox3.Text = "出现错误:"+ax.Message.ToString();
- }
- }
- private void button2_Click(object sender, System.EventArgs e)
- {
- textBox3.Text= "";
- textBox2.Text= "";
- textBox1.Text= "";
- }
- }
- }