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

📄 richtextboxextended.cs

📁 C#编写文本编辑器源码
💻 CS
📖 第 1 页 / 共 4 页
字号:
using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;
using System.Threading;
using System.Text;

namespace RichTextBoxExtended
{
   	#region StampActions
	public enum StampActions
	{
		EditedBy = 1,
		DateTime = 2,
		Custom = 4
	}
	#endregion

	/// <summary>
	/// An extended RichTextBox that contains a toolbar.
	/// </summary>
	public class RichTextBoxExtended : System.Windows.Forms.UserControl
	{
		//Used for looping
		private RichTextBox rtbTemp = new RichTextBox();

		#region Windows Generated
		private System.Windows.Forms.ToolBar tb1;
		private System.Windows.Forms.RichTextBox rtb1;
		private System.Windows.Forms.ImageList imgList1;
		private System.Windows.Forms.ToolBarButton tbbBold;
		private System.Windows.Forms.ToolBarButton tbbItalic;
		private System.Windows.Forms.ToolBarButton tbbUnderline;
		private System.Windows.Forms.ToolBarButton tbbCenter;
		private System.Windows.Forms.ToolBarButton tbbRight;
		private System.Windows.Forms.ToolBarButton tbbStrikeout;
		private System.Windows.Forms.ToolBarButton tbbColor;
		private System.Windows.Forms.ContextMenu cmColors;
		private System.Windows.Forms.MenuItem miBlack;
		private System.Windows.Forms.MenuItem miBlue;
		private System.Windows.Forms.MenuItem miRed;
		private System.Windows.Forms.MenuItem miGreen;
		private System.Windows.Forms.ToolBarButton tbbStamp;
		private System.Windows.Forms.ToolBarButton tbbOpen;
		private System.Windows.Forms.ToolBarButton tbbSave;
		private System.Windows.Forms.ToolBarButton tbbUndo;
		private System.Windows.Forms.ToolBarButton tbbRedo;
		private System.Windows.Forms.ToolBarButton tbbSeparator2;
		private System.Windows.Forms.ToolBarButton tbbSeparator3;
		private System.Windows.Forms.ToolBarButton tbbSeparator4;
		private System.Windows.Forms.ToolBarButton tbbSeparator1;
		private System.Windows.Forms.ToolBarButton tbbLeft;
		private System.Windows.Forms.OpenFileDialog ofd1;
		private System.Windows.Forms.SaveFileDialog sfd1;
		private System.Windows.Forms.ContextMenu cmFonts;
		private System.Windows.Forms.MenuItem miArial;
		private System.Windows.Forms.MenuItem miGaramond;
		private System.Windows.Forms.MenuItem miTahoma;
		private System.Windows.Forms.MenuItem miTimesNewRoman;
		private System.Windows.Forms.MenuItem miVerdana;
		private System.Windows.Forms.ToolBarButton tbbFont;
		private System.Windows.Forms.ToolBarButton tbbFontSize;
		private System.Windows.Forms.ToolBarButton tbbSeparator5;
		private System.Windows.Forms.MenuItem miCourierNew;
		private System.Windows.Forms.MenuItem miMicrosoftSansSerif;
		private System.Windows.Forms.ContextMenu cmFontSizes;
		private System.Windows.Forms.MenuItem mi8;
		private System.Windows.Forms.MenuItem mi9;
		private System.Windows.Forms.MenuItem mi10;
		private System.Windows.Forms.MenuItem mi11;
		private System.Windows.Forms.MenuItem mi12;
		private System.Windows.Forms.MenuItem mi14;
		private System.Windows.Forms.MenuItem mi16;
		private System.Windows.Forms.MenuItem mi18;
		private System.Windows.Forms.MenuItem mi20;
		private System.Windows.Forms.MenuItem mi22;
		private System.Windows.Forms.MenuItem mi24;
		private System.Windows.Forms.MenuItem mi26;
		private System.Windows.Forms.MenuItem mi28;
		private System.Windows.Forms.MenuItem mi36;
		private System.Windows.Forms.MenuItem mi48;
		private System.Windows.Forms.MenuItem mi72;
		private System.ComponentModel.IContainer components;
		private System.Windows.Forms.ToolBarButton tbbCut;
		private System.Windows.Forms.ToolBarButton tbbCopy;
		private System.Windows.Forms.ToolBarButton tbbPaste;

		public RichTextBoxExtended()
		{
			// This call is required by the Windows.Forms Form Designer.
			InitializeComponent();

			//Update the graphics on the toolbar
			UpdateToolbar();
		}

		/// <summary> 
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}
		#endregion

		#region Component Designer generated code
		/// <summary> 
		/// Required method for Designer support - do not modify 
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			this.components = new System.ComponentModel.Container();
			System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(RichTextBoxExtended));
			this.tb1 = new System.Windows.Forms.ToolBar();
			this.tbbSave = new System.Windows.Forms.ToolBarButton();
			this.tbbOpen = new System.Windows.Forms.ToolBarButton();
			this.tbbSeparator3 = new System.Windows.Forms.ToolBarButton();
			this.tbbFont = new System.Windows.Forms.ToolBarButton();
			this.cmFonts = new System.Windows.Forms.ContextMenu();
			this.miArial = new System.Windows.Forms.MenuItem();
			this.miCourierNew = new System.Windows.Forms.MenuItem();
			this.miGaramond = new System.Windows.Forms.MenuItem();
			this.miMicrosoftSansSerif = new System.Windows.Forms.MenuItem();
			this.miTahoma = new System.Windows.Forms.MenuItem();
			this.miTimesNewRoman = new System.Windows.Forms.MenuItem();
			this.miVerdana = new System.Windows.Forms.MenuItem();
			this.tbbFontSize = new System.Windows.Forms.ToolBarButton();
			this.cmFontSizes = new System.Windows.Forms.ContextMenu();
			this.mi8 = new System.Windows.Forms.MenuItem();
			this.mi9 = new System.Windows.Forms.MenuItem();
			this.mi10 = new System.Windows.Forms.MenuItem();
			this.mi11 = new System.Windows.Forms.MenuItem();
			this.mi12 = new System.Windows.Forms.MenuItem();
			this.mi14 = new System.Windows.Forms.MenuItem();
			this.mi16 = new System.Windows.Forms.MenuItem();
			this.mi18 = new System.Windows.Forms.MenuItem();
			this.mi20 = new System.Windows.Forms.MenuItem();
			this.mi22 = new System.Windows.Forms.MenuItem();
			this.mi24 = new System.Windows.Forms.MenuItem();
			this.mi26 = new System.Windows.Forms.MenuItem();
			this.mi28 = new System.Windows.Forms.MenuItem();
			this.mi36 = new System.Windows.Forms.MenuItem();
			this.mi48 = new System.Windows.Forms.MenuItem();
			this.mi72 = new System.Windows.Forms.MenuItem();
			this.tbbColor = new System.Windows.Forms.ToolBarButton();
			this.cmColors = new System.Windows.Forms.ContextMenu();
			this.miBlack = new System.Windows.Forms.MenuItem();
			this.miBlue = new System.Windows.Forms.MenuItem();
			this.miRed = new System.Windows.Forms.MenuItem();
			this.miGreen = new System.Windows.Forms.MenuItem();
			this.tbbSeparator5 = new System.Windows.Forms.ToolBarButton();
			this.tbbBold = new System.Windows.Forms.ToolBarButton();
			this.tbbItalic = new System.Windows.Forms.ToolBarButton();
			this.tbbUnderline = new System.Windows.Forms.ToolBarButton();
			this.tbbStrikeout = new System.Windows.Forms.ToolBarButton();
			this.tbbSeparator1 = new System.Windows.Forms.ToolBarButton();
			this.tbbLeft = new System.Windows.Forms.ToolBarButton();
			this.tbbCenter = new System.Windows.Forms.ToolBarButton();
			this.tbbRight = new System.Windows.Forms.ToolBarButton();
			this.tbbSeparator2 = new System.Windows.Forms.ToolBarButton();
			this.tbbUndo = new System.Windows.Forms.ToolBarButton();
			this.tbbRedo = new System.Windows.Forms.ToolBarButton();
			this.tbbSeparator4 = new System.Windows.Forms.ToolBarButton();
			this.tbbCut = new System.Windows.Forms.ToolBarButton();
			this.tbbCopy = new System.Windows.Forms.ToolBarButton();
			this.tbbPaste = new System.Windows.Forms.ToolBarButton();
			this.tbbStamp = new System.Windows.Forms.ToolBarButton();
			this.imgList1 = new System.Windows.Forms.ImageList(this.components);
			this.rtb1 = new System.Windows.Forms.RichTextBox();
			this.ofd1 = new System.Windows.Forms.OpenFileDialog();
			this.sfd1 = new System.Windows.Forms.SaveFileDialog();
			this.SuspendLayout();
			// 
			// tb1
			// 
			this.tb1.Appearance = System.Windows.Forms.ToolBarAppearance.Flat;
			this.tb1.Buttons.AddRange(new System.Windows.Forms.ToolBarButton[] {
																				   this.tbbSave,
																				   this.tbbOpen,
																				   this.tbbSeparator3,
																				   this.tbbFont,
																				   this.tbbFontSize,
																				   this.tbbColor,
																				   this.tbbSeparator5,
																				   this.tbbBold,
																				   this.tbbItalic,
																				   this.tbbUnderline,
																				   this.tbbStrikeout,
																				   this.tbbSeparator1,
																				   this.tbbLeft,
																				   this.tbbCenter,
																				   this.tbbRight,
																				   this.tbbSeparator2,
																				   this.tbbUndo,
																				   this.tbbRedo,
																				   this.tbbSeparator4,
																				   this.tbbCut,
																				   this.tbbCopy,
																				   this.tbbPaste,
																				   this.tbbStamp});
			this.tb1.ButtonSize = new System.Drawing.Size(16, 16);
			this.tb1.Divider = false;
			this.tb1.DropDownArrows = true;
			this.tb1.ImageList = this.imgList1;
			this.tb1.Location = new System.Drawing.Point(0, 0);
			this.tb1.Name = "tb1";
			this.tb1.ShowToolTips = true;
			this.tb1.Size = new System.Drawing.Size(504, 26);
			this.tb1.TabIndex = 0;
			this.tb1.ButtonClick += new System.Windows.Forms.ToolBarButtonClickEventHandler(this.tb1_ButtonClick);
			// 
			// tbbSave
			// 
			this.tbbSave.ImageIndex = 11;
			this.tbbSave.Tag = "save";
			// 
			// tbbOpen
			// 
			this.tbbOpen.ImageIndex = 10;
			this.tbbOpen.Tag = "open";
			// 
			// tbbSeparator3
			// 
			this.tbbSeparator3.Style = System.Windows.Forms.ToolBarButtonStyle.Separator;
			// 
			// tbbFont
			// 
			this.tbbFont.DropDownMenu = this.cmFonts;
			this.tbbFont.ImageIndex = 14;
			this.tbbFont.Style = System.Windows.Forms.ToolBarButtonStyle.DropDownButton;
			this.tbbFont.Tag = "font";
			// 
			// cmFonts
			// 
			this.cmFonts.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
																					this.miArial,
																					this.miCourierNew,
																					this.miGaramond,
																					this.miMicrosoftSansSerif,
																					this.miTahoma,
																					this.miTimesNewRoman,
																					this.miVerdana});
			// 
			// miArial
			// 
			this.miArial.Index = 0;
			this.miArial.Text = "Arial";
			this.miArial.Click += new System.EventHandler(this.Font_Click);
			// 
			// miCourierNew
			// 
			this.miCourierNew.Index = 1;
			this.miCourierNew.Text = "Courier New";
			this.miCourierNew.Click += new System.EventHandler(this.Font_Click);
			// 
			// miGaramond
			// 
			this.miGaramond.Index = 2;
			this.miGaramond.Text = "Garamond";
			this.miGaramond.Click += new System.EventHandler(this.Font_Click);
			// 
			// miMicrosoftSansSerif
			// 
			this.miMicrosoftSansSerif.Index = 3;
			this.miMicrosoftSansSerif.Text = "Microsoft Sans Serif";
			this.miMicrosoftSansSerif.Click += new System.EventHandler(this.Font_Click);
			// 
			// miTahoma
			// 
			this.miTahoma.Index = 4;
			this.miTahoma.Text = "Tahoma";
			this.miTahoma.Click += new System.EventHandler(this.Font_Click);
			// 
			// miTimesNewRoman
			// 
			this.miTimesNewRoman.Index = 5;
			this.miTimesNewRoman.Text = "Times New Roman";
			this.miTimesNewRoman.Click += new System.EventHandler(this.Font_Click);
			// 
			// miVerdana
			// 
			this.miVerdana.Index = 6;
			this.miVerdana.Text = "Verdana";
			this.miVerdana.Click += new System.EventHandler(this.Font_Click);
			// 
			// tbbFontSize
			// 
			this.tbbFontSize.DropDownMenu = this.cmFontSizes;
			this.tbbFontSize.ImageIndex = 15;
			this.tbbFontSize.Style = System.Windows.Forms.ToolBarButtonStyle.DropDownButton;
			this.tbbFontSize.Tag = "font size";
			// 
			// cmFontSizes
			// 
			this.cmFontSizes.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
																						this.mi8,
																						this.mi9,
																						this.mi10,
																						this.mi11,
																						this.mi12,
																						this.mi14,
																						this.mi16,
																						this.mi18,
																						this.mi20,
																						this.mi22,
																						this.mi24,
																						this.mi26,
																						this.mi28,
																						this.mi36,
																						this.mi48,
																						this.mi72});
			// 
			// mi8
			// 
			this.mi8.Index = 0;
			this.mi8.Text = "8";
			this.mi8.Click += new System.EventHandler(this.FontSize_Click);
			// 
			// mi9
			// 
			this.mi9.Index = 1;
			this.mi9.Text = "9";
			this.mi9.Click += new System.EventHandler(this.FontSize_Click);
			// 
			// mi10
			// 
			this.mi10.Index = 2;
			this.mi10.Text = "10";
			this.mi10.Click += new System.EventHandler(this.FontSize_Click);
			// 
			// mi11
			// 
			this.mi11.Index = 3;
			this.mi11.Text = "11";
			this.mi11.Click += new System.EventHandler(this.FontSize_Click);
			// 
			// mi12
			// 
			this.mi12.Index = 4;
			this.mi12.Text = "12";
			this.mi12.Click += new System.EventHandler(this.FontSize_Click);
			// 
			// mi14
			// 
			this.mi14.Index = 5;
			this.mi14.Text = "14";
			this.mi14.Click += new System.EventHandler(this.FontSize_Click);
			// 
			// mi16
			// 
			this.mi16.Index = 6;
			this.mi16.Text = "16";
			this.mi16.Click += new System.EventHandler(this.FontSize_Click);
			// 
			// mi18
			// 
			this.mi18.Index = 7;
			this.mi18.Text = "18";
			this.mi18.Click += new System.EventHandler(this.FontSize_Click);
			// 
			// mi20
			// 
			this.mi20.Index = 8;
			this.mi20.Text = "20";
			this.mi20.Click += new System.EventHandler(this.FontSize_Click);
			// 
			// mi22
			// 
			this.mi22.Index = 9;
			this.mi22.Text = "22";
			this.mi22.Click += new System.EventHandler(this.FontSize_Click);
			// 
			// mi24

⌨️ 快捷键说明

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