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

📄 text.cs

📁 C#做的一个文本编辑器
💻 CS
📖 第 1 页 / 共 3 页
字号:
			// helpMenu
			// 
			this.helpMenu.Index = 4;
			this.helpMenu.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
																					 this.menuItem2,
																					 this.menuItem3});
			this.helpMenu.Shortcut = System.Windows.Forms.Shortcut.CtrlH;
			this.helpMenu.Text = "帮助";
			this.helpMenu.Click += new System.EventHandler(this.helpMenu_Click);
			// 
			// menuItem2
			// 
			this.menuItem2.Index = 0;
			this.menuItem2.Text = "使用说明";
			this.menuItem2.Click += new System.EventHandler(this.menuItem2_Click);
			// 
			// menuItem3
			// 
			this.menuItem3.Index = 1;
			this.menuItem3.Text = "关于软件";
			this.menuItem3.Click += new System.EventHandler(this.menuItem3_Click);
			// 
			// content
			// 
			this.content.Dock = System.Windows.Forms.DockStyle.Fill;
			this.content.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.content.Location = new System.Drawing.Point(0, 0);
			this.content.Multiline = true;
			this.content.Name = "content";
			this.content.Size = new System.Drawing.Size(496, 352);
			this.content.TabIndex = 0;
			this.content.Text = "";
			// 
			// mystatusBar
			// 
			this.mystatusBar.Location = new System.Drawing.Point(0, 330);
			this.mystatusBar.Name = "mystatusBar";
			this.mystatusBar.Panels.AddRange(new System.Windows.Forms.StatusBarPanel[] {
																						   this.statusBarPanel1,
																						   this.statusBarPanel2,
																						   this.statusBarPanel3,
																						   this.statusBarPanel4});
			this.mystatusBar.ShowPanels = true;
			this.mystatusBar.Size = new System.Drawing.Size(496, 22);
			this.mystatusBar.TabIndex = 1;
			this.mystatusBar.Text = "就绪";
			this.mystatusBar.PanelClick += new System.Windows.Forms.StatusBarPanelClickEventHandler(this.mystatusBar_PanelClick);
			// 
			// statusBarPanel1
			// 
			this.statusBarPanel1.Alignment = System.Windows.Forms.HorizontalAlignment.Center;
			this.statusBarPanel1.AutoSize = System.Windows.Forms.StatusBarPanelAutoSize.Spring;
			this.statusBarPanel1.Text = "就绪";
			this.statusBarPanel1.Width = 125;
			// 
			// statusBarPanel2
			// 
			this.statusBarPanel2.Width = 200;
			// 
			// statusBarPanel3
			// 
			this.statusBarPanel3.Alignment = System.Windows.Forms.HorizontalAlignment.Right;
			this.statusBarPanel3.AutoSize = System.Windows.Forms.StatusBarPanelAutoSize.Spring;
			this.statusBarPanel3.Width = 125;
			// 
			// statusBarPanel4
			// 
			this.statusBarPanel4.Width = 30;
			// 
			// notifyIcon1
			// 
			this.notifyIcon1.Text = "notifyIcon1";
			this.notifyIcon1.Visible = true;
			// 
			// toolBar1
			// 
			this.toolBar1.Buttons.AddRange(new System.Windows.Forms.ToolBarButton[] {
																						this.NewFileButton,
																						this.OpenFileButton,
																						this.SaveFileButton,
																						this.PrintButton,
																						this.CloseFileButton});
			this.toolBar1.DropDownArrows = true;
			this.toolBar1.ImageList = this.imageList1;
			this.toolBar1.Location = new System.Drawing.Point(0, 0);
			this.toolBar1.Name = "toolBar1";
			this.toolBar1.ShowToolTips = true;
			this.toolBar1.Size = new System.Drawing.Size(496, 28);
			this.toolBar1.TabIndex = 3;
			this.toolBar1.TextAlign = System.Windows.Forms.ToolBarTextAlign.Right;
			this.toolBar1.ButtonClick += new System.Windows.Forms.ToolBarButtonClickEventHandler(this.toolBar1_ButtonClick);
			// 
			// NewFileButton
			// 
			this.NewFileButton.ImageIndex = 4;
			this.NewFileButton.ToolTipText = "新建文档";
			// 
			// OpenFileButton
			// 
			this.OpenFileButton.ImageIndex = 1;
			this.OpenFileButton.ToolTipText = "打开文档";
			// 
			// SaveFileButton
			// 
			this.SaveFileButton.Enabled = false;
			this.SaveFileButton.ImageIndex = 0;
			this.SaveFileButton.ToolTipText = "保存文档";
			// 
			// PrintButton
			// 
			this.PrintButton.Enabled = false;
			this.PrintButton.ImageIndex = 2;
			this.PrintButton.ToolTipText = "打印文档";
			// 
			// CloseFileButton
			// 
			this.CloseFileButton.Enabled = false;
			this.CloseFileButton.ImageIndex = 3;
			this.CloseFileButton.ToolTipText = "关闭当前文档";
			// 
			// imageList1
			// 
			this.imageList1.ImageSize = new System.Drawing.Size(16, 16);
			this.imageList1.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("imageList1.ImageStream")));
			this.imageList1.TransparentColor = System.Drawing.Color.Transparent;
			// 
			// tabControl1
			// 
			this.tabControl1.Dock = System.Windows.Forms.DockStyle.Fill;
			this.tabControl1.ImageList = this.imageList1;
			this.tabControl1.Location = new System.Drawing.Point(0, 28);
			this.tabControl1.Name = "tabControl1";
			this.tabControl1.SelectedIndex = 0;
			this.tabControl1.Size = new System.Drawing.Size(496, 302);
			this.tabControl1.TabIndex = 9;
			// 
			// tabPage1
			// 
			this.tabPage1.Location = new System.Drawing.Point(0, 0);
			this.tabPage1.Name = "tabPage1";
			this.tabPage1.TabIndex = 0;
			// 
			// richTextBox1
			// 
			this.richTextBox1.Location = new System.Drawing.Point(0, 0);
			this.richTextBox1.Name = "richTextBox1";
			this.richTextBox1.TabIndex = 0;
			this.richTextBox1.Text = "";
			// 
			// printDocument1
			// 
			this.printDocument1.BeginPrint += new System.Drawing.Printing.PrintEventHandler(this.printDocument1_BeginPrint);
			this.printDocument1.EndPrint += new System.Drawing.Printing.PrintEventHandler(this.printDocument1_EndPrint);
			this.printDocument1.PrintPage += new System.Drawing.Printing.PrintPageEventHandler(this.printDocument1_PrintPage);
			// 
			// printPreviewDialog1
			// 
			this.printPreviewDialog1.AutoScrollMargin = new System.Drawing.Size(0, 0);
			this.printPreviewDialog1.AutoScrollMinSize = new System.Drawing.Size(0, 0);
			this.printPreviewDialog1.ClientSize = new System.Drawing.Size(400, 300);
			this.printPreviewDialog1.Enabled = true;
			this.printPreviewDialog1.Icon = ((System.Drawing.Icon)(resources.GetObject("printPreviewDialog1.Icon")));
			this.printPreviewDialog1.Location = new System.Drawing.Point(44, 60);
			this.printPreviewDialog1.MinimumSize = new System.Drawing.Size(375, 250);
			this.printPreviewDialog1.Name = "printPreviewDialog1";
			this.printPreviewDialog1.TransparencyKey = System.Drawing.Color.Empty;
			this.printPreviewDialog1.Visible = false;
			// 
			// timer1
			// 
			this.timer1.Enabled = true;
			this.timer1.Interval = 1000;
			this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
			// 
			// myText
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.ClientSize = new System.Drawing.Size(496, 352);
			this.Controls.Add(this.tabControl1);
			this.Controls.Add(this.toolBar1);
			this.Controls.Add(this.mystatusBar);
			this.Controls.Add(this.content);
			this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
			this.Menu = this.mainMenu1;
			this.Name = "myText";
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
			this.Text = "Text";
			this.Closing += new System.ComponentModel.CancelEventHandler(this.myText_Closing);
			((System.ComponentModel.ISupportInitialize)(this.statusBarPanel1)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.statusBarPanel2)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.statusBarPanel3)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.statusBarPanel4)).EndInit();
			this.ResumeLayout(false);

		}
		#endregion


//*********************************************文件菜单区*****************************************************
		private RichTextBox  MakeNewTbpage(string pageName)//新建一个文档实现
		{	//增加选项卡页TabPage
			TabPage tabPage1=new TabPage();
			tabControl1.Controls.Add(tabPage1);//将tabPage1放到tabControl1中
			tabPage1.Location=new Point(4, 21);
			tabPage1.Size=new Size(284, 248);
			if(pageName == "")
			{
				tabPage1.Text="新文档"+(tabPage1.TabIndex+1).ToString();
			}
			else
			{
				tabPage1.Text=pageName;
				tabPage1.Name=pageName;	
			}
			//增加RichTextBox
			RichTextBox richTextBox1=new RichTextBox();
			richTextBox1.BackColor=Color.LightCyan;
			richTextBox1.Dock=DockStyle.Fill;
			richTextBox1.Size=new Size(284, 248);
			richTextBox1.Text="";
			tabPage1.Controls.Add(richTextBox1);//将richTextBox1放到tabPage1中
			this.tabControl1.SelectedTab = tabPage1;
			saveMenuItem.Enabled = true;
			saveAsMenuItem.Enabled = true;
			printMenuItem.Enabled = true;
			previewItem.Enabled = true;
			copyMenuItem.Enabled = true;
			pasteMenuItem.Enabled = true;
			cutMenuItem.Enabled = true;
			findMenuItem.Enabled = true;
			replaseMenuItem.Enabled = true;
			colorMenuItem.Enabled = true;
			fontMenuItem.Enabled = true;
			toolBar1.Buttons[2].Enabled = true;
			toolBar1.Buttons[3].Enabled = true;
			toolBar1.Buttons[4].Enabled = true;
			return richTextBox1;
		}


		private void newMenuItem_Click(object sender, System.EventArgs e)//新建
		{
			mystatusBar.Panels[0].Text="新建文档工作中";
			MakeNewTbpage("");
			mystatusBar.Panels[0].Text="就绪";
		}

		private void openMenueItem_Click(object sender, System.EventArgs e)//打开
		{
			Stream myStream;
            mystatusBar.Panels[0].Text="打开文件工作中";
			OpenFileDialog open=new OpenFileDialog();

			//设置初始时的文件目录
			open.InitialDirectory="C:\\";
			//设置过滤文件的文件类型
			open.Filter="文本文件(*.txt)|*.txt|其他文件(*.*)|*.*";
			open.ShowReadOnly=false;
			if(open.ShowDialog()==DialogResult.OK)
			{
				try
				{
					if((myStream=open.OpenFile())!=null)
					{
						line=new ArrayList();
						StreamReader myStreamReader=new StreamReader(myStream,System.Text.Encoding.GetEncoding("GB2312"));
						while((contentLine=myStreamReader.ReadLine())!=null)
						{
							
							if(contentLine.Length==0)
							{
								continue;
							}
							else
							{
								line.Add(contentLine);
								//MessageBox.Show(contentLine);
							}
						}//while
						myStreamReader.Close();
						//string b = open.FileName;
						//int a =  b.LastIndexOf("\\");
						string fileName = open.FileName.Remove(0,open.FileName.LastIndexOf("\\")+1);
						RichTextBox box = MakeNewTbpage(fileName);
						
						for(int index=0;index<line.Count;index++)
						{
							string temp;
							temp=(string)line[index];
							temp=temp+"\n";
							box.AppendText(temp);
							box.Name=open.FileName;
							//MessageBox.Show(temp);
						}
					}//if
					
				}//try
				catch(IOException ioe)
				{
					string temp=ioe.ToString();
					MessageBox.Show(temp);
				}
				catch(ArgumentNullException ane)
				{
					string temp=ane.ToString();
					MessageBox.Show(temp);
				}
				catch(ArgumentException ae)
				{
					string temp=ae.ToString();
					MessageBox.Show(temp);
				}
				catch(Exception exc)
				{
					string temp=exc.ToString();
					MessageBox.Show(temp);
				}
			}
			mystatusBar.Panels[0].Text="就绪";
		}
		private void saveMenuItem_Click(object sender, System.EventArgs e)//保存
		{
			mystatusBar.Panels[0].Text="文件保存作业中";
			TabPage tabPage1=tabControl1.SelectedTab;//得到当前选定的选项卡页
			RichTextBox richTextBox1=(RichTextBox)tabPage1.Controls[0];//得到当前选定的选项卡页中第0个控件,即RichTextBox控件
			if(tabPage1.Name.Length!=0)
				richTextBox1.SaveFile(tabPage1.Name,RichTextBoxStreamType.PlainText);
			else
				saveAsMenuItem_Click(sender,e);

⌨️ 快捷键说明

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