📄 form2.cs
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.IO;
namespace htmlMaker
{
/// <summary>
/// Form2 的摘要说明。
/// </summary>
public class Form2 : System.Windows.Forms.Form
{
private System.Windows.Forms.TextBox txbFilename;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Button open;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.Label label5;
private System.Windows.Forms.TextBox chaxun;
private System.Windows.Forms.Button kaishichaxun;
private System.Windows.Forms.OpenFileDialog openFileDialog1;
private System.Windows.Forms.StatusBar statusBar1;
private System.Windows.Forms.RichTextBox richTextBox1;
private System.Windows.Forms.Button updata;
private System.Windows.Forms.Button delete;
private System.Windows.Forms.Button close;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
public Form2()
{
//
// 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()
{
this.txbFilename = new System.Windows.Forms.TextBox();
this.label2 = new System.Windows.Forms.Label();
this.label1 = new System.Windows.Forms.Label();
this.open = new System.Windows.Forms.Button();
this.updata = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.label5 = new System.Windows.Forms.Label();
this.chaxun = new System.Windows.Forms.TextBox();
this.kaishichaxun = new System.Windows.Forms.Button();
this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog();
this.statusBar1 = new System.Windows.Forms.StatusBar();
this.richTextBox1 = new System.Windows.Forms.RichTextBox();
this.delete = new System.Windows.Forms.Button();
this.close = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// txbFilename
//
this.txbFilename.Enabled = false;
this.txbFilename.Location = new System.Drawing.Point(80, 16);
this.txbFilename.Name = "txbFilename";
this.txbFilename.Size = new System.Drawing.Size(184, 21);
this.txbFilename.TabIndex = 11;
this.txbFilename.Text = "";
//
// label2
//
this.label2.Location = new System.Drawing.Point(24, 24);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(48, 16);
this.label2.TabIndex = 8;
this.label2.Text = "文件名";
//
// label1
//
this.label1.Location = new System.Drawing.Point(24, 96);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(56, 16);
this.label1.TabIndex = 9;
this.label1.Text = "查询结果";
//
// open
//
this.open.Location = new System.Drawing.Point(272, 16);
this.open.Name = "open";
this.open.Size = new System.Drawing.Size(32, 24);
this.open.TabIndex = 16;
this.open.Text = "...";
this.open.Click += new System.EventHandler(this.open_Click);
//
// updata
//
this.updata.Location = new System.Drawing.Point(16, 208);
this.updata.Name = "updata";
this.updata.Size = new System.Drawing.Size(72, 24);
this.updata.TabIndex = 17;
this.updata.Text = "操作";
this.updata.Click += new System.EventHandler(this.button1_Click);
//
// button2
//
this.button2.Location = new System.Drawing.Point(88, 208);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(72, 24);
this.button2.TabIndex = 18;
this.button2.Text = "修改";
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// label5
//
this.label5.Location = new System.Drawing.Point(24, 160);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(64, 16);
this.label5.TabIndex = 19;
this.label5.Text = "查询编号:";
//
// chaxun
//
this.chaxun.Location = new System.Drawing.Point(80, 152);
this.chaxun.Name = "chaxun";
this.chaxun.Size = new System.Drawing.Size(176, 21);
this.chaxun.TabIndex = 20;
this.chaxun.Text = "";
//
// kaishichaxun
//
this.kaishichaxun.Location = new System.Drawing.Point(264, 152);
this.kaishichaxun.Name = "kaishichaxun";
this.kaishichaxun.Size = new System.Drawing.Size(40, 24);
this.kaishichaxun.TabIndex = 21;
this.kaishichaxun.Text = "搜";
this.kaishichaxun.Click += new System.EventHandler(this.kaishichaxun_Click);
//
// statusBar1
//
this.statusBar1.Location = new System.Drawing.Point(0, 246);
this.statusBar1.Name = "statusBar1";
this.statusBar1.Size = new System.Drawing.Size(320, 16);
this.statusBar1.TabIndex = 22;
this.statusBar1.Text = "statusBar1";
//
// richTextBox1
//
this.richTextBox1.Enabled = false;
this.richTextBox1.Location = new System.Drawing.Point(80, 48);
this.richTextBox1.Name = "richTextBox1";
this.richTextBox1.Size = new System.Drawing.Size(224, 88);
this.richTextBox1.TabIndex = 23;
this.richTextBox1.Text = "";
//
// delete
//
this.delete.Location = new System.Drawing.Point(160, 208);
this.delete.Name = "delete";
this.delete.Size = new System.Drawing.Size(72, 24);
this.delete.TabIndex = 24;
this.delete.Text = "删除";
this.delete.Click += new System.EventHandler(this.delete_Click);
//
// close
//
this.close.Location = new System.Drawing.Point(232, 208);
this.close.Name = "close";
this.close.Size = new System.Drawing.Size(72, 24);
this.close.TabIndex = 25;
this.close.Text = "退出";
this.close.Click += new System.EventHandler(this.close_Click);
//
// Form2
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(320, 262);
this.Controls.Add(this.close);
this.Controls.Add(this.delete);
this.Controls.Add(this.richTextBox1);
this.Controls.Add(this.statusBar1);
this.Controls.Add(this.kaishichaxun);
this.Controls.Add(this.chaxun);
this.Controls.Add(this.label5);
this.Controls.Add(this.button2);
this.Controls.Add(this.updata);
this.Controls.Add(this.open);
this.Controls.Add(this.txbFilename);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;
this.Name = "Form2";
this.Text = "学生信息修改";
this.ResumeLayout(false);
}
#endregion
private void open_Click(object sender, System.EventArgs e)
{
statusBar1.Text = "打开文件";
if (openFileDialog1.ShowDialog () == DialogResult.OK )
{
txbFilename.Text = (openFileDialog1.FileName);
System.IO.StreamReader streamReader = new StreamReader(openFileDialog1.FileName,System.Text.Encoding.UTF8);
string sLine = string.Empty;
while((sLine = streamReader.ReadLine()) != null)
{
richTextBox1.Text += sLine + "\r\n";
}
//richTextBox1.LoadFile (streamReader.BaseStream ,RichTextBoxStreamType.PlainText);
}
}
private int FindPlace = 0;//从头开始找起
private void kaishichaxun_Click(object sender, System.EventArgs e)
{
statusBar1.Text = "正在查找中.....";
if (chaxun.Text == "")
{
MessageBox.Show("请输入要查找的内容!","警告",MessageBoxButtons.OKCancel,MessageBoxIcon.Warning);
}
else
{
Form2 mainForm =(Form2)this.Owner;
if (richTextBox1.Text.Length == 0) //如果文本内容为空,则提示错误,内容为空。
{
MessageBox.Show("要查找的文本内容为空,不能查找!","错误提示",MessageBoxButtons.OKCancel,MessageBoxIcon.Warning);
}
else //查找。。。。
{
if ((FindPlace = richTextBox1.Text.IndexOf (chaxun.Text ,FindPlace)) == -1)
{
MessageBox.Show ("查找结束,没有搜索到你所要找的内容!","查找结果");
FindPlace = 0; //没有找到,重置查找位置为文本起点
}
else
{
richTextBox1.Select(FindPlace,chaxun.Text.Length);
//找到了,置查找位置为下一个位置
FindPlace = FindPlace + richTextBox1.Text .Length ;
Activate ();
}
}
}
}
private void button1_Click(object sender, System.EventArgs e)
{
richTextBox1.Enabled = true;
}
private void button2_Click(object sender, System.EventArgs e)
{
//richTextBox1.SaveFile(openFileDialog1.FileName);
bool GenerateCode = true;
if( GenerateCode )
{
statusBar1.Text = "文件保存成功" + txbFilename.Text;
richTextBox1.SaveFile(openFileDialog1.FileName,RichTextBoxStreamType.PlainText );
}
else
{
statusBar1.Text = "文件保存失败!";
}
}
private void delete_Click(object sender, System.EventArgs e)
{
if (richTextBox1.SelectedText != "" )
{
richTextBox1.SelectedText="";
richTextBox1.SaveFile(openFileDialog1.FileName,RichTextBoxStreamType.PlainText );
statusBar1.Text = "文件保存成功" + txbFilename.Text;
}
}
private void close_Click(object sender, System.EventArgs e)
{
this.Hide();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -