标签:
public partial class Form2 : Form { public Form2() { InitializeComponent(); } private Form1 jishiben; public Form2(Form1 f) { InitializeComponent(); jishiben = f; } public int index = -1; private void cha_Click(object sender, EventArgs e) { string mubiao = txtchazhao.Text; string yuanshuju = jishiben.txtjishiben.Text; index = yuanshuju.IndexOf(mubiao,index+1); if (index > -1) { jishiben.txtjishiben.Select(index, mubiao.Length); jishiben.Focus(); } } private void tihuan_Click(object sender, EventArgs e) { jishiben.txtjishiben.Text = jishiben.txtjishiben.Text.Replace(txtchazhao.Text,txttihuan.Text); } }
public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void 打开OToolStripMenuItem_Click(object sender, EventArgs e) { openFileDialog1.Filter = "文本文档|*.txt|所有文件|*.*"; DialogResult isok = openFileDialog1.ShowDialog(); if (isok == DialogResult.OK) { string filePath = openFileDialog1.FileName; this.txtjishiben.Text = File.ReadAllText(filePath, Encoding.Default); this.Text = new FileInfo(filePath).Name;//获取文件名 } } private void 新建NToolStripMenuItem_Click(object sender, EventArgs e) { this.txtjishiben.Text=""; } private void 另存为AToolStripMenuItem_Click(object sender, EventArgs e) { saveFileDialog1.Filter = "文本文档|*.txt|所有文件|*.*"; DialogResult isok = saveFileDialog1.ShowDialog(); if (isok == DialogResult.OK) { string filename = saveFileDialog1.FileName; //StreamWriter sw = new StreamWriter(filename); //sw.Write(this.txtjishiben.Text); //sw.Close(); File.WriteAllText(filename,this.txtjishiben.Text,Encoding.Default); } } private void 保存SToolStripMenuItem_Click(object sender, EventArgs e) { string path = openFileDialog1.FileName; string n = this.txtjishiben.Text; File.WriteAllText(path, n,Encoding.Default); } private void 退出XToolStripMenuItem_Click(object sender, EventArgs e) { this.Close(); } private void 打印PToolStripMenuItem_Click(object sender, EventArgs e) { printDialog1.Document = printDocument1; DialogResult isok = printDialog1.ShowDialog(); if (isok == DialogResult.OK) { printDocument1.Print(); } } private void 打印预览VToolStripMenuItem_Click(object sender, EventArgs e) { printPreviewDialog1.ShowDialog(); printPreviewDialog1.Document = printDocument1; } private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e) { System.Drawing.Font f=new System.Drawing.Font("隶书",19.8f); e.Graphics.DrawString(this.txtjishiben.Text,f,System.Drawing.Brushes.Blue,new Point(100,100)); ; } private void 查找ToolStripMenuItem_Click(object sender, EventArgs e) { Form2 f = new Form2(this); f.Show(); } }
标签:
原文地址:http://www.cnblogs.com/liujianshe1990-/p/5122801.html