📄 form1.cs
字号:
this.label2.Text = "文 本:";
//
// txtRegex
//
this.txtRegex.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.txtRegex.BackColor = System.Drawing.SystemColors.ControlLight;
this.txtRegex.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.txtRegex.Font = new System.Drawing.Font("宋体", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.txtRegex.Location = new System.Drawing.Point(84, 12);
this.txtRegex.Name = "txtRegex";
this.txtRegex.Size = new System.Drawing.Size(390, 23);
this.txtRegex.TabIndex = 2;
this.txtRegex.Text = "";
//
// statusBar1
//
this.statusBar1.Location = new System.Drawing.Point(0, 311);
this.statusBar1.Name = "statusBar1";
this.statusBar1.Panels.AddRange(new System.Windows.Forms.StatusBarPanel[] {
this.statusDesc,
this.statusBarPanel1,
this.statusTime});
this.statusBar1.ShowPanels = true;
this.statusBar1.Size = new System.Drawing.Size(544, 22);
this.statusBar1.TabIndex = 4;
this.statusBar1.Text = "statusBar1";
//
// statusDesc
//
this.statusDesc.BorderStyle = System.Windows.Forms.StatusBarPanelBorderStyle.None;
this.statusDesc.Text = "您若是有什么意见,请一定给我发信!谢谢!!";
this.statusDesc.Width = 320;
//
// statusBarPanel1
//
this.statusBarPanel1.BorderStyle = System.Windows.Forms.StatusBarPanelBorderStyle.None;
this.statusBarPanel1.Text = "现在日期时间:";
this.statusBarPanel1.Width = 90;
//
// statusTime
//
this.statusTime.BorderStyle = System.Windows.Forms.StatusBarPanelBorderStyle.None;
this.statusTime.Width = 120;
//
// btnStart
//
this.btnStart.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.btnStart.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.btnStart.Location = new System.Drawing.Point(490, 12);
this.btnStart.Name = "btnStart";
this.btnStart.Size = new System.Drawing.Size(40, 23);
this.btnStart.TabIndex = 7;
this.btnStart.Text = "开始";
this.btnStart.TextAlign = System.Drawing.ContentAlignment.TopCenter;
this.btnStart.Click += new System.EventHandler(this.btnStart_Click);
//
// txtText
//
this.txtText.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.txtText.BackColor = System.Drawing.SystemColors.ControlLight;
this.txtText.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.txtText.Font = new System.Drawing.Font("宋体", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.txtText.Location = new System.Drawing.Point(84, 52);
this.txtText.Multiline = true;
this.txtText.Name = "txtText";
this.txtText.ScrollBars = System.Windows.Forms.ScrollBars.Both;
this.txtText.Size = new System.Drawing.Size(446, 248);
this.txtText.TabIndex = 5;
this.txtText.Text = "";
//
// timer1
//
this.timer1.Enabled = true;
this.timer1.Interval = 1000;
this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
//
// helpProvider1
//
this.helpProvider1.HelpNamespace = "help.chm";
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.BackColor = System.Drawing.SystemColors.Control;
this.ClientSize = new System.Drawing.Size(544, 333);
this.Controls.Add(this.txtText);
this.Controls.Add(this.btnStart);
this.Controls.Add(this.statusBar1);
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.Menu = this.mainMenu1;
this.Name = "Form1";
this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "正则表达式学习工具 Version1.0";
this.Load += new System.EventHandler(this.Form1_Load);
((System.ComponentModel.ISupportInitialize)(this.statusDesc)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.statusBarPanel1)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.statusTime)).EndInit();
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
//查看典型正则表达式
private void menuItem17_Click(object sender, System.EventArgs e)
{
//DataForm df = new DataForm();
//df.Show();
DataR d = new DataR();
d.form1 = this;
d.Show();
}
/// <summary>
/// 关闭程序
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void menuItem7_Click(object sender, System.EventArgs e)
{
this.Close();
}
/// <summary>
/// 进行正则表达式匹配事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnStart_Click(object sender, System.EventArgs e)
{
string strRegex =@txtRegex.Text.Trim();
string strText = txtText.Text.Trim();
if ( strRegex!="" || strText!="" )
{
RegexFac regexFac = new RegexFac( strRegex, IsUL, IsComment );
Regex regex = regexFac.GetRegex();
MatchCollection matches = regex.Matches(strText);
Result result = new Result();
result.Show();
string head = "共找到" + matches.Count + "组匹配!\r\n";
result.textBox1.AppendText(head);
for ( int i=0; i<matches.Count; i++ )
{
string str =" 位置:"+matches[i].Index+" 文本:"+matches[i].Value.ToString()+"\n";
result.textBox1.AppendText((i+1)+":\n");
result.textBox1.AppendText(str);
}
}
else
{
MessageBox.Show("正则表达式或匹配文本不能为空!!","错误提示!");
}
}
//区分大小写选择
private void menuItem12_Click(object sender, System.EventArgs e)
{
menuItem12.Checked = !menuItem12.Checked;
IsUL = !IsUL;
}
//使用注释选择
private void menuItem13_Click(object sender, System.EventArgs e)
{
menuItem13.Checked = !menuItem13.Checked;
IsComment = !IsComment;
}
//程序加载时,检查大小写,注释。
private void Form1_Load(object sender, System.EventArgs e)
{
IsUL = (menuItem12.Checked==true);
IsComment = (menuItem13.Checked==true);
}
//关于窗口
private void menuItem10_Click(object sender, System.EventArgs e)
{
about ab = new about();
ab.Show();
}
//替换窗口。
private void menuItem11_Click(object sender, System.EventArgs e)
{
Replace replace = new Replace();
replace.Show();
}
//读取文件到文本框
private void menuItem4_Click(object sender, System.EventArgs e)
{
openFile.Filter = "文本文件(*.txt)|*.txt|所有文件(*.*)|*.*";
try
{
if ( openFile.ShowDialog() == DialogResult.OK )
{
//读取文本内容到文本框
string filePath = openFile.FileName;
FileStream fs = new FileStream( filePath, FileMode.Open);
StreamReader sw = new StreamReader( fs, Encoding.Default );
string text = sw.ReadToEnd();
this.txtText.Text = text;
}
}
catch ( Exception eee )
{
MessageBox.Show(eee.Message.ToString() );
}
}
//编译配置
private void menuItem15_Click(object sender, System.EventArgs e)
{
Complie comp = new Complie();
comp.txtReg = this.txtRegex;
comp.Show();
}
private void timer1_Tick(object sender, System.EventArgs e)
{
string time = System.DateTime.Now.ToString();
statusBar1.Panels[2].Text = time;
}
private void menuItem8_Click(object sender, System.EventArgs e)
{
System.Diagnostics.Process.Start("help.htm");
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -