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

📄 form1.cs

📁 一个小记事本,有待完善
💻 CS
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace WordPad
{
	/// <summary>
	/// Form1 的摘要说明。
	/// </summary>
	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.MenuItem menuItem8;
		private System.Windows.Forms.MenuItem menuItem9;
		private System.Windows.Forms.MenuItem menuItem10;
		private System.Windows.Forms.MenuItem menuItem11;
		private System.Windows.Forms.RichTextBox rtb;
		private System.Windows.Forms.OpenFileDialog openFileDialog1;
		private System.Windows.Forms.SaveFileDialog saveFileDialog1;
		private System.Windows.Forms.FontDialog fontDialog1;
		private System.Windows.Forms.ColorDialog colorDialog1;
		/// <summary>
		/// 必需的设计器变量。
		/// </summary>
		private System.ComponentModel.Container components = null;

		public Form1()
		{
			//
			// 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.mainMenu1 = new System.Windows.Forms.MainMenu();
			this.menuItem1 = new System.Windows.Forms.MenuItem();
			this.menuItem2 = new System.Windows.Forms.MenuItem();
			this.menuItem3 = new System.Windows.Forms.MenuItem();
			this.menuItem11 = 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.menuItem8 = new System.Windows.Forms.MenuItem();
			this.menuItem9 = new System.Windows.Forms.MenuItem();
			this.menuItem10 = new System.Windows.Forms.MenuItem();
			this.rtb = new System.Windows.Forms.RichTextBox();
			this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog();
			this.saveFileDialog1 = new System.Windows.Forms.SaveFileDialog();
			this.fontDialog1 = new System.Windows.Forms.FontDialog();
			this.colorDialog1 = new System.Windows.Forms.ColorDialog();
			this.SuspendLayout();
			// 
			// mainMenu1
			// 
			this.mainMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
																					  this.menuItem1,
																					  this.menuItem4,
																					  this.menuItem8});
			// 
			// menuItem1
			// 
			this.menuItem1.Index = 0;
			this.menuItem1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
																					  this.menuItem2,
																					  this.menuItem3,
																					  this.menuItem11});
			this.menuItem1.Text = "&File";
			// 
			// menuItem2
			// 
			this.menuItem2.Index = 0;
			this.menuItem2.Shortcut = System.Windows.Forms.Shortcut.CtrlO;
			this.menuItem2.Text = "&Open";
			this.menuItem2.Click += new System.EventHandler(this.menuFileOpen_Click);
			// 
			// menuItem3
			// 
			this.menuItem3.Index = 1;
			this.menuItem3.Shortcut = System.Windows.Forms.Shortcut.CtrlS;
			this.menuItem3.Text = "&Save";
			this.menuItem3.Click += new System.EventHandler(this.menuFileSave_Click);
			// 
			// menuItem11
			// 
			this.menuItem11.Index = 2;
			this.menuItem11.Text = "&Exit";
			this.menuItem11.Click += new System.EventHandler(this.menuExit_Click);
			// 
			// menuItem4
			// 
			this.menuItem4.Index = 1;
			this.menuItem4.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
																					  this.menuItem5,
																					  this.menuItem6,
																					  this.menuItem7});
			this.menuItem4.Text = "&Edit";
			// 
			// menuItem5
			// 
			this.menuItem5.Index = 0;
			this.menuItem5.Shortcut = System.Windows.Forms.Shortcut.CtrlX;
			this.menuItem5.Text = "&Cut";
			this.menuItem5.Click += new System.EventHandler(this.menuEditCut_Click);
			// 
			// menuItem6
			// 
			this.menuItem6.Index = 1;
			this.menuItem6.Shortcut = System.Windows.Forms.Shortcut.CtrlC;
			this.menuItem6.Text = "&Copy";
			this.menuItem6.Click += new System.EventHandler(this.menuEditCopy_Click);
			// 
			// menuItem7
			// 
			this.menuItem7.Index = 2;
			this.menuItem7.Shortcut = System.Windows.Forms.Shortcut.CtrlV;
			this.menuItem7.Text = "&Paste";
			this.menuItem7.Click += new System.EventHandler(this.menuEditPaste_Click);
			// 
			// menuItem8
			// 
			this.menuItem8.Index = 2;
			this.menuItem8.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
																					  this.menuItem9,
																					  this.menuItem10});
			this.menuItem8.Text = "&Format";
			// 
			// menuItem9
			// 
			this.menuItem9.Index = 0;
			this.menuItem9.Text = "&Font";
			this.menuItem9.Click += new System.EventHandler(this.menuFormatFont_Click);
			// 
			// menuItem10
			// 
			this.menuItem10.Index = 1;
			this.menuItem10.Text = "&Color";
			this.menuItem10.Click += new System.EventHandler(this.menuFormatColor_Click);
			// 
			// rtb
			// 
			this.rtb.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.rtb.AutoSize = true;
			this.rtb.Font = new System.Drawing.Font("宋体", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.rtb.Location = new System.Drawing.Point(4, 8);
			this.rtb.Name = "rtb";
			this.rtb.Size = new System.Drawing.Size(600, 340);
			this.rtb.TabIndex = 0;
			this.rtb.Text = "";
			this.rtb.TextChanged += new System.EventHandler(this.rtb_TextChanged);
			// 
			// Form1
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.ClientSize = new System.Drawing.Size(592, 353);
			this.Controls.Add(this.rtb);
			this.Menu = this.mainMenu1;
			this.Name = "Form1";
			this.Text = "我的记事本";
			this.Load += new System.EventHandler(this.Form1_Load);
			this.ResumeLayout(false);

		}
		#endregion

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

		private void menuFileOpen_Click(object sender, System.EventArgs e)
		{
			openFileDialog1.InitialDirectory = Application.ExecutablePath;
			openFileDialog1.DefaultExt = "rtf";
			openFileDialog1.FileName = "";
			openFileDialog1.Filter = 
				"text (*.txt) | *.txt";
			openFileDialog1.ShowDialog();
			rtb.LoadFile(openFileDialog1.FileName);
		}

		private void menuFileSave_Click(object sender, System.EventArgs e)
		{
			saveFileDialog1.InitialDirectory = Application.ExecutablePath;
			saveFileDialog1.DefaultExt = "rtf";
			saveFileDialog1.FileName = "purple";
			saveFileDialog1.Filter = 
				"Rich Text Files (*.rtf) | *.rtf|All files (*.*) | (*.*)";
			saveFileDialog1.ShowDialog();
			rtb.SaveFile(saveFileDialog1.FileName);
		}

		private void menuExit_Click(object sender, System.EventArgs e)
		{
			
		}

		private void listView1_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			
		}

		private void menuEditCut_Click(object sender, System.EventArgs e)
		{
			rtb.Cut();
		}

		private void menuEditCopy_Click(object sender, System.EventArgs e)
		{
			rtb.Copy();
		}

		private void menuEditPaste_Click(object sender, System.EventArgs e)
		{
			rtb.Paste();
		}

		private void menuFormatFont_Click(object sender, System.EventArgs e)
		{
			fontDialog1.ShowDialog();
			rtb.SelectionFont = fontDialog1.Font;
		}

		private void menuFormatColor_Click(object sender, System.EventArgs e)
		{
			colorDialog1.AllowFullOpen = true;
			colorDialog1.AnyColor = true;
			colorDialog1.ShowDialog();
			rtb.SelectionColor = colorDialog1.Color;
		}

		private void rtb_TextChanged(object sender, System.EventArgs e)
		{
		
		}

		private void Form1_Load(object sender, System.EventArgs e)
		{
		
		}
	}
}

⌨️ 快捷键说明

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