简易文本编辑器 C#源码

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace EditerApp
{
 ///
 /// Form1 的摘要说明。
 ///
 public class Form1 : System.Windows.Forms.Form
 {
  private System.Windows.Forms.MainMenu mainMenu1;
  private System.Windows.Forms.MenuItem menuItem1;
  private System.Windows.Forms.MenuItem menuItem2;
  private System.Windows.Forms.MenuItem menuItem3;
  private System.Windows.Forms.MenuItem menuItem4;
  private System.Windows.Forms.MenuItem menuItem5;
  private System.Windows.Forms.MenuItem menuItem6;
  private System.Windows.Forms.MenuItem menuItem7;
  private System.Windows.Forms.OpenFileDialog openFileDialog1;
  private System.Windows.Forms.SaveFileDialog saveFileDialog1;
  private System.Windows.Forms.RichTextBox MyRTBox;
  private System.Windows.Forms.StatusBar MyStatus;
  ///
  /// 必需的设计器变量。
  ///
  private System.ComponentModel.Container components = null;

  public Form1()
  {
   //
   // Windows 窗体设计器支持所必需的
   //
   InitializeComponent();

   //
   // TODO: 在 InitializeComponent 调用后添加任何构造函数代码
   //
  }

  ///
  /// 清理所有正在使用的资源。
  ///
  protected override void Dispose( bool disposing )
  {
   if( disposing )
   {
    if (components != null)
    {
     components.Dispose();
    }
   }
   base.Dispose( disposing );
  }

  #region Windows Form Designer generated code
  ///
  /// 设计器支持所需的方法 - 不要使用代码编辑器修改
  /// 此方法的内容。
  ///
  private void InitializeComponent()
  {
   this.MyRTBox = new System.Windows.Forms.RichTextBox();
   this.MyStatus = new System.Windows.Forms.StatusBar();
   this.mainMenu1 = new System.Windows.Forms.MainMenu();
   this.menuItem1 = new System.Windows.Forms.MenuItem();
   this.menuItem3 = new System.Windows.Forms.MenuItem();
   this.menuItem2 = new System.Windows.Forms.MenuItem();
   this.menuItem4 = new System.Windows.Forms.MenuItem();
   this.menuItem5 = new System.Windows.Forms.MenuItem();
   this.menuItem6 = new System.Windows.Forms.MenuItem();
   this.menuItem7 = new System.Windows.Forms.MenuItem();
   this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog();
   this.saveFileDialog1 = new System.Windows.Forms.SaveFileDialog();
   this.SuspendLayout();
   //
   // MyRTBox
   //
   this.MyRTBox.Dock = System.Windows.Forms.DockStyle.Fill;
   this.MyRTBox.Name = "MyRTBox";
   this.MyRTBox.Size = new System.Drawing.Size(292, 273);
   this.MyRTBox.TabIndex = 0;
   this.MyRTBox.Text = "";
   //
   // MyStatus
   //
   this.MyStatus.Location = new System.Drawing.Point(0, 251);
   this.MyStatus.Name = "MyStatus";
   this.MyStatus.Size = new System.Drawing.Size(292, 22);
   this.MyStatus.TabIndex = 1;
   this.MyStatus.Text = "新建文件";
   //
   // mainMenu1
   //
   this.mainMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
                       this.menuItem1,
                       this.menuItem7});
   //
   // menuItem1
   //
   this.menuItem1.Index = 0;
   this.menuItem1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
                       this.menuItem3,
                       this.menuItem2,
                       this.menuItem4,
                       this.menuItem5,
                       this.menuItem6});
   this.menuItem1.Text = "文件(&F)";
   //
   // menuItem3
   //
   this.menuItem3.Index = 0;
   this.menuItem3.Text = "新建(&N)";
   this.menuItem3.Click += new System.EventHandler(this.menuItem3_Click);
   //
   // menuItem2
   //
   this.menuItem2.Index = 1;
   this.menuItem2.Text = "打开(&O)";
   this.menuItem2.Click += new System.EventHandler(this.menuItem2_Click);
   //
   // menuItem4
   //
   this.menuItem4.Index = 2;
   this.menuItem4.Text = "保存(&S)";
   this.menuItem4.Click += new System.EventHandler(this.menuItem4_Click);
   //
   // menuItem5
   //
   this.menuItem5.Index = 3;
   this.menuItem5.Text = "-";
   //
   // menuItem6
   //
   this.menuItem6.Index = 4;
   this.menuItem6.Text = "退出(&X)";
   this.menuItem6.Click += new System.EventHandler(this.menuItem6_Click);
   //
   // menuItem7
   //
   this.menuItem7.Index = 1;
   this.menuItem7.Text = "关于(&A)";
   //
   // openFileDialog1
   //
   this.openFileDialog1.Filter = "Text Files(*.txt)|*.txt|Rich Text Format Files(*.rtf)|*.rtf|All Files(*.*)|*.*";
   //
   // saveFileDialog1
   //
   this.saveFileDialog1.FileName = "doc1";
   this.saveFileDialog1.Filter = "Text Files(*.txt)|*.txt|Rich Text Format Files(*.rtf)|*.rtf|All Files(*.*)|*.*";
   //
   // Form1
   //
   this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
   this.ClientSize = new System.Drawing.Size(292, 273);
   this.Controls.AddRange(new System.Windows.Forms.Control[] {
                    this.MyStatus,
                    this.MyRTBox});
   this.Menu = this.mainMenu1;
   this.Name = "Form1";
   this.Text = "EditorApp";
   this.ResumeLayout(false);

  }
  #endregion

  ///
  /// 应用程序的主入口点。
  ///
  [STAThread]
  static void Main()
  {
   Application.Run(new Form1());
  }

  private void CheckSave()
  {
   if (MyRTBox.Text != "")
   {
    if (MessageBox.Show ("是否保存当前文件?","确认" ,MessageBoxButtons.OKCancel  ) == DialogResult.OK )
    {
     MySaveFile();
    }
   }
  }

  private void MyNewFile()
  {
   CheckSave(); //检查是否保存当前文件
   MyRTBox.Clear ();
   MyStatus.Text = "新建文件";
  }

  private void MySaveFile()
  {
   MyStatus.Text = "保存文件";
   if (saveFileDialog1.ShowDialog () == DialogResult.OK )
   {
    MyRTBox.SaveFile (saveFileDialog1.FileName );
   }
  }
  private void MyOpenFile()
  {
   CheckSave(); //检查是否保存当前文件
   
   if (openFileDialog1.ShowDialog () == DialogResult.OK )
   {
    MyRTBox.LoadFile (openFileDialog1.FileName ,RichTextBoxStreamType.PlainText );
    MyStatus.Text = "打开文件";
   } 
  }
  private void MyExit()
  {
   CheckSave(); //检查是否保存当前文件

   Application.Exit ();
  }

  private void menuItem3_Click(object sender, System.EventArgs e)
  {
   MyNewFile(); //新建文件
  }

  private void menuItem2_Click(object sender, System.EventArgs e)
  {   
   MyOpenFile();//打开文件 
  }

  private void menuItem4_Click(object sender, System.EventArgs e)
  {
   MySaveFile();//保存文件
  }

  private void menuItem6_Click(object sender, System.EventArgs e)
  {
   MyExit();//退出程序
  }
 }
}

posted on 2008-09-17 00:37 VocanoLee 阅读( ...) 评论( ...) 编辑 收藏

转载于:https://www.cnblogs.com/VocanoLee/archive/2008/09/17/1292122.html

自己的程序源码namespace zdm { partial class formFindReplace { /// /// 必需的设计器变量。 /// private System.ComponentModel.IContainer components = null; /// /// 清理所有正在使用的资源。 /// /// 如果应释放托管资源,为 true;否则为 false。 protected override void Dispose(bool disposing) { if (disposing && (components != null)) { components.Dispose(); } base.Dispose(disposing); } #region Windows 窗体设计器生成的代码 /// /// 设计器支持所需的方法 - 不要 /// 使用代码编辑器修改此方法的内容。 /// private void InitializeComponent() { this.label1 = new System.Windows.Forms.Label(); this.label2 = new System.Windows.Forms.Label(); this.textBox1 = new System.Windows.Forms.TextBox(); this.textBox2 = new System.Windows.Forms.TextBox(); this.buttonFind = new System.Windows.Forms.Button(); this.buttonReplace = new System.Windows.Forms.Button(); this.SuspendLayout(); // // label1 // this.label1.AutoSize = true; this.label1.Location = new System.Drawing.Point(35, 15); this.label1.Name = "label1"; this.label1.Size = new System.Drawing.Size(65, 12); this.label1.TabIndex = 0; this.label1.Text = "查找字符串"; // // label2 // this.label2.AutoSize = true; this.label2.Location = new System.Drawing.Point(35, 60); this.label2.Name = "label2"; this.label2.Size = new System.Drawing.Size(65, 12); this.label2.TabIndex = 1; this.label2.Text = "替换字符串"; // // textBox1 // this.textBox1.Location = new System.Drawing.Point(135, 12); this.textBox1.Name = "textBox1"; this.textBox1.Size = new System.Drawing.Size(120, 21); this.textBox1.TabIndex = 2; // // textBox2 // this.textBox2.Location = new System.Drawing.Point(135, 51); this.textBox2.Name = "textBox2"; this.textBox2.Size = new System.Drawing.Size(120, 21); this.textBox2.TabIndex = 3; // // buttonFind // this.buttonFind.Location = new System.Drawing.Point(49, 110); this.buttonFind.Name = "buttonFind"; this.buttonFind.Size = new System.Drawing.Size(75, 23); this.buttonFind.TabIndex = 4; this.buttonFind.Text = "查找下一处"; this.buttonFind.UseVisualStyleBackColor = true; this.buttonFind.Click += new System.EventHandler(this.buttonFind_Click); // // buttonReplace // this.buttonReplace.Location = new System.Drawing.Point(164, 110); this.buttonReplace.Name = "buttonReplace"; this.buttonReplace.Size = new System.Drawing.Size(91, 23); this.buttonReplace.TabIndex = 5; this.buttonReplace.Text = "替换查到字符"; this.buttonReplace.UseVisualStyleBackColor = true; this.buttonReplace.Click += new System.EventHandler(this.buttonReplace_Click); // // formFindReplace // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(292, 169); this.Controls.Add(this.buttonReplace); this.Controls.Add(this.buttonFind); this.Controls.Add(this.textBox2); this.Controls.Add(this.textBox1); this.Controls.Add(this.label2); this.Controls.Add(this.label1); this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog; this.MaximizeBox = false; this.MinimizeBox = false; this.Name = "formFindReplace"; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; this.Text = "查找和替换"; this.TopMost = true; this.ResumeLayout(false); this.PerformLayout(); } #endregion private System.Windows.Forms.Label label1; private System.Windows.Forms.Label label2; private System.Windows.Forms.TextBox textBox1; private System.Windows.Forms.TextBox textBox2; private System.Windows.Forms.Button buttonFind; private System.Windows.Forms.Button buttonReplace; } }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值