⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 notepad.cs

📁 人事管理系统 时间比较长乐! 不过还算经典 有兴趣看一
💻 CS
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.IO;

namespace Employee
{
	/// <summary>
	/// NotePad 的摘要说明。
	/// </summary>
	public class NotePad : System.Windows.Forms.Form
	{
		private System.Windows.Forms.MainMenu NotePadmainMenu;
		private System.Windows.Forms.OpenFileDialog NotePadopenFileDialog;
		private System.Windows.Forms.SaveFileDialog NotePadsaveFileDialog;
		private System.Windows.Forms.FontDialog NotePadfontDialog;
		private System.Windows.Forms.MenuItem menuItem1;
		private System.Windows.Forms.MenuItem menuItem6;
		private System.Windows.Forms.MenuItem menuItem9;
		private System.Windows.Forms.MenuItem menuItem11;
		private System.Windows.Forms.MenuItem menuItem13;
		private System.Windows.Forms.MenuItem menuItem18;
		private System.Windows.Forms.MenuItem menuItem21;
		private System.Windows.Forms.MenuItem menuItem24;
		private System.Windows.Forms.MenuItem menuItem25;
		private System.Windows.Forms.RichTextBox richtb;
		private System.Windows.Forms.MenuItem Mnew;
		private System.Windows.Forms.MenuItem Mopen;
		private System.Windows.Forms.MenuItem Msave;
		private System.Windows.Forms.MenuItem Msaveas;
		private System.Windows.Forms.MenuItem Mpageset;
		private System.Windows.Forms.MenuItem Mprint;
		private System.Windows.Forms.MenuItem Mexit;
		private System.Windows.Forms.MenuItem Mdo;
		private System.Windows.Forms.MenuItem Mcut;
		private System.Windows.Forms.MenuItem Mcopy;
		private System.Windows.Forms.MenuItem Mpaste;
		private System.Windows.Forms.MenuItem Mdel;
		private System.Windows.Forms.MenuItem Mselectall;
		private System.Windows.Forms.MenuItem Mtime;
		private System.Windows.Forms.MenuItem Mwrap;
		private System.Windows.Forms.MenuItem Mfont;
		/// <summary>
		/// 必需的设计器变量。
		/// </summary>
		private System.ComponentModel.Container components = null;

		public NotePad()
		{
			//
			// 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()
		{
			System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(NotePad));
			this.NotePadmainMenu = new System.Windows.Forms.MainMenu();
			this.menuItem1 = new System.Windows.Forms.MenuItem();
			this.Mnew = new System.Windows.Forms.MenuItem();
			this.Mopen = new System.Windows.Forms.MenuItem();
			this.Msave = new System.Windows.Forms.MenuItem();
			this.Msaveas = new System.Windows.Forms.MenuItem();
			this.menuItem6 = new System.Windows.Forms.MenuItem();
			this.Mpageset = new System.Windows.Forms.MenuItem();
			this.Mprint = new System.Windows.Forms.MenuItem();
			this.menuItem9 = new System.Windows.Forms.MenuItem();
			this.Mexit = new System.Windows.Forms.MenuItem();
			this.menuItem11 = new System.Windows.Forms.MenuItem();
			this.Mdo = new System.Windows.Forms.MenuItem();
			this.menuItem13 = new System.Windows.Forms.MenuItem();
			this.Mcut = new System.Windows.Forms.MenuItem();
			this.Mcopy = new System.Windows.Forms.MenuItem();
			this.Mpaste = new System.Windows.Forms.MenuItem();
			this.Mdel = new System.Windows.Forms.MenuItem();
			this.menuItem18 = new System.Windows.Forms.MenuItem();
			this.Mselectall = new System.Windows.Forms.MenuItem();
			this.Mtime = new System.Windows.Forms.MenuItem();
			this.menuItem21 = new System.Windows.Forms.MenuItem();
			this.Mwrap = new System.Windows.Forms.MenuItem();
			this.Mfont = new System.Windows.Forms.MenuItem();
			this.menuItem24 = new System.Windows.Forms.MenuItem();
			this.menuItem25 = new System.Windows.Forms.MenuItem();
			this.NotePadopenFileDialog = new System.Windows.Forms.OpenFileDialog();
			this.NotePadsaveFileDialog = new System.Windows.Forms.SaveFileDialog();
			this.NotePadfontDialog = new System.Windows.Forms.FontDialog();
			this.richtb = new System.Windows.Forms.RichTextBox();
			this.SuspendLayout();
			// 
			// NotePadmainMenu
			// 
			this.NotePadmainMenu.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
																							this.menuItem1,
																							this.menuItem11,
																							this.menuItem21,
																							this.menuItem24});
			// 
			// menuItem1
			// 
			this.menuItem1.Index = 0;
			this.menuItem1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
																					  this.Mnew,
																					  this.Mopen,
																					  this.Msave,
																					  this.Msaveas,
																					  this.menuItem6,
																					  this.Mpageset,
																					  this.Mprint,
																					  this.menuItem9,
																					  this.Mexit});
			this.menuItem1.Text = "文件";
			// 
			// Mnew
			// 
			this.Mnew.Index = 0;
			this.Mnew.Text = "新建";
			this.Mnew.Click += new System.EventHandler(this.Mnew_Click);
			// 
			// Mopen
			// 
			this.Mopen.Index = 1;
			this.Mopen.Text = "打开";
			this.Mopen.Click += new System.EventHandler(this.Mopen_Click);
			// 
			// Msave
			// 
			this.Msave.Index = 2;
			this.Msave.Text = "保存";
			this.Msave.Click += new System.EventHandler(this.Msave_Click);
			// 
			// Msaveas
			// 
			this.Msaveas.Index = 3;
			this.Msaveas.Text = "另存为";
			this.Msaveas.Click += new System.EventHandler(this.Msaveas_Click);
			// 
			// menuItem6
			// 
			this.menuItem6.Index = 4;
			this.menuItem6.Text = "-";
			// 
			// Mpageset
			// 
			this.Mpageset.Index = 5;
			this.Mpageset.Text = "页面设置";
			// 
			// Mprint
			// 
			this.Mprint.Index = 6;
			this.Mprint.Text = "打印";
			// 
			// menuItem9
			// 
			this.menuItem9.Index = 7;
			this.menuItem9.Text = "-";
			// 
			// Mexit
			// 
			this.Mexit.Index = 8;
			this.Mexit.Text = "退出";
			this.Mexit.Click += new System.EventHandler(this.Mexit_Click);
			// 
			// menuItem11
			// 
			this.menuItem11.Index = 1;
			this.menuItem11.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
																					   this.Mdo,
																					   this.menuItem13,
																					   this.Mcut,
																					   this.Mcopy,
																					   this.Mpaste,
																					   this.Mdel,
																					   this.menuItem18,
																					   this.Mselectall,
																					   this.Mtime});
			this.menuItem11.Text = "编辑";
			// 
			// Mdo
			// 
			this.Mdo.Index = 0;
			this.Mdo.Text = "撒消";
			this.Mdo.Click += new System.EventHandler(this.Mdo_Click);
			// 
			// menuItem13
			// 
			this.menuItem13.Index = 1;
			this.menuItem13.Text = "-";
			// 
			// Mcut
			// 
			this.Mcut.Enabled = false;
			this.Mcut.Index = 2;
			this.Mcut.Text = "剪切";
			this.Mcut.Click += new System.EventHandler(this.Mcut_Click);
			// 
			// Mcopy
			// 
			this.Mcopy.Enabled = false;
			this.Mcopy.Index = 3;
			this.Mcopy.Text = "复制";
			this.Mcopy.Click += new System.EventHandler(this.Mcopy_Click);
			// 
			// Mpaste
			// 
			this.Mpaste.Index = 4;
			this.Mpaste.Text = "粘贴";
			this.Mpaste.Click += new System.EventHandler(this.Mpaste_Click);
			// 
			// Mdel
			// 
			this.Mdel.Enabled = false;
			this.Mdel.Index = 5;
			this.Mdel.Text = "删除";
			this.Mdel.Click += new System.EventHandler(this.Mdel_Click);
			// 
			// menuItem18
			// 
			this.menuItem18.Index = 6;
			this.menuItem18.Text = "-";
			// 
			// Mselectall
			// 
			this.Mselectall.Index = 7;
			this.Mselectall.Text = "全选";
			this.Mselectall.Click += new System.EventHandler(this.Mselectall_Click);
			// 
			// Mtime
			// 
			this.Mtime.Index = 8;
			this.Mtime.Text = "时间/时间  &F5";
			this.Mtime.Click += new System.EventHandler(this.Mtime_Click);
			// 
			// menuItem21
			// 
			this.menuItem21.Index = 2;
			this.menuItem21.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
																					   this.Mwrap,
																					   this.Mfont});
			this.menuItem21.Text = "格式";
			// 
			// Mwrap
			// 
			this.Mwrap.Checked = true;
			this.Mwrap.Index = 0;
			this.Mwrap.Text = "自动换行";
			this.Mwrap.Click += new System.EventHandler(this.Mwrap_Click);
			// 
			// Mfont
			// 
			this.Mfont.Index = 1;
			this.Mfont.Text = "字体";
			this.Mfont.Click += new System.EventHandler(this.Mfont_Click);
			// 
			// menuItem24
			// 
			this.menuItem24.Index = 3;
			this.menuItem24.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
																					   this.menuItem25});
			this.menuItem24.Text = "帮助";
			// 
			// menuItem25
			// 
			this.menuItem25.Index = 0;
			this.menuItem25.Text = "关于";
			this.menuItem25.Click += new System.EventHandler(this.menuItem25_Click);
			// 
			// NotePadsaveFileDialog
			// 
			this.NotePadsaveFileDialog.FileName = "doc.txt";
			this.NotePadsaveFileDialog.Filter = "*.txt|*.*";
			this.NotePadsaveFileDialog.Title = "保存为";
			// 
			// richtb
			// 
			this.richtb.BackColor = System.Drawing.Color.Bisque;
			this.richtb.Dock = System.Windows.Forms.DockStyle.Fill;
			this.richtb.Location = new System.Drawing.Point(0, 0);
			this.richtb.Name = "richtb";
			this.richtb.Size = new System.Drawing.Size(452, 373);
			this.richtb.TabIndex = 0;
			this.richtb.Text = "";
			this.richtb.SelectionChanged += new System.EventHandler(this.richtb_SelectionChanged);
			// 
			// NotePad
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.ClientSize = new System.Drawing.Size(452, 373);
			this.Controls.Add(this.richtb);
			this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
			this.Menu = this.NotePadmainMenu;
			this.Name = "NotePad";
			this.Text = "员工查询系统    记事本";
			this.ResumeLayout(false);

		}
		#endregion

		private void Mnew_Click(object sender, System.EventArgs e)
		{
			richtb.Text="";
		}

		private void Mopen_Click(object sender, System.EventArgs e)
		{
			if(NotePadopenFileDialog.ShowDialog()==DialogResult.OK)
			{
				StreamReader sr = new StreamReader(NotePadopenFileDialog.FileName,System.Text.Encoding.Default);
				richtb.Text=sr.ReadToEnd();
				sr.Close();
			}
		}

		private void Msave_Click(object sender, System.EventArgs e)
		{
			if(NotePadsaveFileDialog.ShowDialog()==DialogResult.OK)
			{
				StreamWriter sw = new StreamWriter(NotePadsaveFileDialog.FileName);
				sw.Write(richtb.Text);
				sw.Close();
			}
		}

		private void Msaveas_Click(object sender, System.EventArgs e)
		{
			if(NotePadsaveFileDialog.ShowDialog()==DialogResult.OK)
			{
				StreamWriter sw = new StreamWriter(NotePadsaveFileDialog.FileName);
				sw.Write(richtb.Text);
				sw.Close();
			}
		}

		private void Mexit_Click(object sender, System.EventArgs e)
		{
			if(MessageBox.Show("你确认要退出吗?","提示",MessageBoxButtons.YesNo,MessageBoxIcon.Question)==DialogResult.Yes)
			{
				this.Close();
			}
		}

		private void Mdo_Click(object sender, System.EventArgs e)
		{
			richtb.Undo();
		}

		private void Mcut_Click(object sender, System.EventArgs e)
		{
			richtb.Cut();
		}

		private void Mcopy_Click(object sender, System.EventArgs e)
		{
			richtb.Copy();
		}

		private void Mpaste_Click(object sender, System.EventArgs e)
		{
			richtb.Paste();
		}

		private void Mdel_Click(object sender, System.EventArgs e)
		{
			if(richtb.SelectedText!="")
			{
				richtb.SelectedText="";
			}
		}

		private void Mselectall_Click(object sender, System.EventArgs e)
		{
			richtb.SelectAll();
		}

		private void Mtime_Click(object sender, System.EventArgs e)
		{
			DateTime dt=DateTime.Now;
			richtb.AppendText(dt.ToString());
		}

		private void Mwrap_Click(object sender, System.EventArgs e)
		{
			Mwrap.Checked=!Mwrap.Checked;;
			if(Mwrap.Checked==true)
			{
				richtb.WordWrap=true;
			}
			else
				richtb.WordWrap=false;
		}

		private void Mfont_Click(object sender, System.EventArgs e)
		{
			if(NotePadfontDialog.ShowDialog()==DialogResult.OK)
			{
				richtb.SelectionFont=NotePadfontDialog.Font;
			}
		}

		private void menuItem25_Click(object sender, System.EventArgs e)
		{
			about aboutform = new about();
			aboutform.ShowDialog();
		}

		private void richtb_SelectionChanged(object sender, System.EventArgs e)
		{
			if(richtb.SelectedText!="")
			{
				Mcut.Enabled=true;
				Mcopy.Enabled=true;
				Mdel.Enabled=true;
			}
			else
			{
				Mcut.Enabled=false;
				Mcopy.Enabled=false;
				Mdel.Enabled=false;
			}
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -