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

📄 form1.cs

📁 多文档编辑,可同时编辑多个文本文档文件,比windows自带的记事本方便多了.
💻 CS
📖 第 1 页 / 共 3 页
字号:
				this.menuItem6.Checked=true;
			}
		}
		//		状态栏的显示和隐藏
		private void menuItem7_Click(object sender, System.EventArgs e)
		{
			if(this.menuItem7.Checked)
			{
				this.statusBar1.Hide();
				this.menuItem7.Checked=false;
			}
			else
			{
				this.statusBar1.Show();
				this.statusBar1.Dock=DockStyle.Bottom;
				this.menuItem7.Checked=true;
			}
		}
//        工具栏上按钮事件
		private void toolBar1_ButtonClick(object sender, System.Windows.Forms.ToolBarButtonClickEventArgs e)
		{
			if(e.Button==this.toolBarButton9)
			{
				Search s=new Search();
				s.Show();
			}
			if(e.Button==this.toolBarButton11)
			{
				this.menuItem13_Click(null,null);
			}
			if(e.Button==this.toolBarButton1)
			{
				this.menuItem2_Click(null,null);
			}
			if(e.Button==this.toolBarButton2)
			{
				this.menuItem3_Click(null,null);
			}
			if(e.Button==this.toolBarButton4)
			{
				SaveFileDialog sfDlg=new SaveFileDialog();
				sfDlg.Filter="Rich text format files(*.rtf)|*.rtf|All files(*.*)|*.*";
				sfDlg.FilterIndex=1;
				sfDlg.DefaultExt="rtf";
				sfDlg.AddExtension=true;
				sfDlg.RestoreDirectory=true;
				if(sfDlg.ShowDialog()==DialogResult.OK)
				{
					((MDIChild)ActiveMdiChild).richTextBox1.SaveFile(sfDlg.FileName);
	
					ActiveMdiChild.Text=sfDlg.FileName;
				}
			}
			else if(e.Button==this.toolBarButton5)
			{
				SaveFileDialog sfDlg=new SaveFileDialog();
				sfDlg.Filter="Rich text format files(*.rtf)|*.rtf|All files(*.*)|*.*";
				sfDlg.FilterIndex=1;
				sfDlg.DefaultExt="rtf";
				sfDlg.AddExtension=true;
				sfDlg.RestoreDirectory=true;
				if(sfDlg.ShowDialog()==DialogResult.OK)
				{
					((MDIChild)ActiveMdiChild).richTextBox1.SaveFile(sfDlg.FileName);
	
					ActiveMdiChild.Text=sfDlg.FileName;
				}
			}
			else if(e.Button==this.toolBarButton7)
			{
				if(ActiveMdiChild!=null)
				{
					((MDIChild)ActiveMdiChild).richTextBox1.Cut();
				}
			}
			else if(e.Button==this.toolBarButton8)
			{
				if(ActiveMdiChild!=null)
				{
					((MDIChild)ActiveMdiChild).richTextBox1.Copy();
				}
			}
			else if(e.Button==this.toolBarButton12)
			{
				if(ActiveMdiChild!=null)
				{
					this.printDialog1.Document=this.printDocument1;
					if(this.printDialog1.ShowDialog()==DialogResult.OK)
					{
						try
						{
							this.printDocument1.Print();
						}
						catch(Exception ex)
						{
							MessageBox.Show(ex.Message,"打印出错",MessageBoxButtons.OK,MessageBoxIcon.Error);
							this.printDocument1.PrintController.OnEndPrint(printDocument1,new System.Drawing.Printing.PrintEventArgs());
						}
					}
				}
				else if(e.Button==this.toolBarButton13)
				{
					if(ActiveMdiChild!=null)
					{
						((MDIChild)ActiveMdiChild).richTextBox1.Paste();
					}
				}
			}
			else if(e.Button==this.toolBarButton14)
			{
				this.process1.StartInfo.FileName="osk.exe";
				this.process1.Start();
			}
			else if(e.Button==this.toolBarButton16)
				{
					this.process1.StartInfo.FileName="magnify.exe";
					this.process1.Start();
				}
				

				
			
        }



		private void timer1_Tick(object sender, System.EventArgs e)
		{
			string time=System.DateTime.Now.ToShortDateString()+"  "+System.DateTime.Now.ToLongTimeString();
			this.statusBarPanel1.Text="当前日期:"+time.ToString();
		}
		private void MDIEditor_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
		{
			this.statusBarPanel3.Text="X:"+e.X.ToString();
			this.statusBarPanel4.Text="Y:"+e.Y.ToString();
		}

		private void menuItem13_Click(object sender, System.EventArgs e)
		{
			MessageBox.Show("多文档界面文本编辑应用软件,1.0版\n免费使用!使用即简单又方便。","关于MDI Text Editor",MessageBoxButtons.OK,MessageBoxIcon.Exclamation);
//			Help.ShowHelp(this,"D:\\WINDOWS\\system32\\calc.chm");
		}
//         自动换行
		private void menuItem19_Click(object sender, System.EventArgs e)
		{
			if(((MDIChild)ActiveMdiChild).richTextBox1.WordWrap==false)
			{
				((MDIChild)ActiveMdiChild).richTextBox1.WordWrap=true;
			}
			else
			{
                   ((MDIChild)ActiveMdiChild).richTextBox1.WordWrap=false;
			}
		}

//		字体的格式设置
		private void menuItem21_Click(object sender, System.EventArgs e)
		{
			if(ActiveMdiChild!=null)
			{
				if(this.fontDialog1.ShowDialog()==DialogResult.OK)
				{
					((MDIChild)ActiveMdiChild).richTextBox1.SelectionFont=this.fontDialog1.Font;
					((MDIChild)ActiveMdiChild).richTextBox1.SelectionColor =this.fontDialog1.Color;
					string fontInfo=this.fontDialog1.Font.Size.ToString();
					MessageBox.Show("You select:"+fontInfo);
					this.fontDialog1.AllowScriptChange=true;

				}
			}
		}

		private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
		{
			Graphics g=e.Graphics;
			float linesPerPage=0;
			float yPosition=0;
			int count=0;
			float leftMargin=e.MarginBounds.Left;
			float topMargin=e.MarginBounds.Top;
			string line=null;
			Font printFont=((MDIChild)ActiveMdiChild).richTextBox1.Font;
			SolidBrush myBrush=new SolidBrush(Color.Black);
			linesPerPage=e.MarginBounds.Height/printFont.GetHeight(g);
			while(count<linesPerPage&&((line=lineReader.ReadLine())!=null))
			{
				yPosition=topMargin+(count*printFont.GetHeight(g));
				g.DrawString(line,printFont,myBrush,leftMargin,yPosition,new StringFormat());
				count++;
			}
			if(line!=null)
			{
				e.HasMorePages=true;
			}
			else
			{
				e.HasMorePages=false;
			}

		}

//		工具栏上的下拉菜单
		private void menuItem22_Click(object sender, System.EventArgs e)
		{
			this.process1.StartInfo.FileName="notepad.exe";
			this.process1.Start();
		}
		private void menuItem23_Click(object sender, System.EventArgs e)
		{
			this.process1.StartInfo.FileName="mspaint.exe";
			this.process1.Start();
		}
		private void menuItem24_Click(object sender, System.EventArgs e)
		{
			try
			{
				this.process1.StartInfo.FileName="Flash.exe";
				this.process1.Start();
			}
			catch(Exception ex)
			{
				MessageBox.Show(ex.Message);
			}
		}

//		设置背景颜色
		public void ChangeSelectedMenuItemMark(object sender)
		{
			this.menuItem26.Checked=false;
			this.menuItem27.Checked=false;
			this.menuItem28.Checked=false;
			((MenuItem)sender).Checked=true;
		}

		private void menuItem26_Click(object sender, System.EventArgs e)
		{
			this.BackColor=Color.MistyRose;

			this.ChangeSelectedMenuItemMark(sender);
		}

		private void menuItem27_Click(object sender, System.EventArgs e)
		{
			this.BackColor= Color.SkyBlue;
			this.ChangeSelectedMenuItemMark(sender);
		}

		private void menuItem28_Click(object sender, System.EventArgs e)
		{
			this.BackColor=Color.YellowGreen;
			this.ChangeSelectedMenuItemMark(sender);
		}
		private void menuItem29_Click(object sender, System.EventArgs e)
		{
		   this.BackColor=Color.Orange;
		   this.ChangeSelectedMenuItemMark(sender);
		}
		private void menuItem30_Click(object sender, System.EventArgs e)
		{
			if(this.colorDialog1.ShowDialog()==DialogResult.OK)
			{
				this.BackColor=this.colorDialog1.Color;
			}
		}


		private void MDIEditor_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
		{
			try
			{
				Graphics g=e.Graphics;
				Rectangle rec=new Rectangle(0,0,1024,768);
				LinearGradientBrush brush=new LinearGradientBrush(rec,Color.OrangeRed,Color.GreenYellow,LinearGradientMode.Horizontal);
				g.FillRectangle(brush,rec);
			}
			catch(Exception ex)
			{
				MessageBox.Show(ex.Message);
			}
		}

		
//      链接的颜色
		private void timer2_Tick(object sender, System.EventArgs e)
		{			
				Random r=new Random();
				int rr=r.Next(0,256);
				int rg=r.Next(0,256);
				int rb=r.Next(0,256);
				this.linkLabel1.BackColor=System.Drawing.Color.FromArgb(rr,rg,rb);
				this.timer2.Enabled=true;
			
		}

//		链接的实现
		private void linkLabel1_LinkClicked(object sender, System.Windows.Forms.LinkLabelLinkClickedEventArgs e)
		{
			System.Diagnostics.Process.Start("www.nyist.net");
		}
//       上下文菜单的实现
		private void menuItem17_Click(object sender, System.EventArgs e)
		{
			if(ActiveMdiChild!=null)
			{
				((MDIChild)ActiveMdiChild).richTextBox1.Paste();
				this.menuItem17.Enabled=true;
			}
			else
			{
				this.menuItem17.Enabled=false;
			}
		}

		private void menuItem15_Click(object sender, System.EventArgs e)
		{
			if(ActiveMdiChild!=null)
			{
				((MDIChild)ActiveMdiChild).richTextBox1.Paste();
				this.menuItem15.Enabled=true;
			}
			else
			{
				this.menuItem15.Enabled=false;
			}
		}

		private void menuItem16_Click(object sender, System.EventArgs e)
		{
			if(ActiveMdiChild!=null)
			{
				((MDIChild)ActiveMdiChild).richTextBox1.Paste();
				this.menuItem16.Enabled=true;
			}
			else
			{
				this.menuItem16.Enabled=false;
			}
		}

		private void menuItem18_Click(object sender, System.EventArgs e)
		{
			if(ActiveMdiChild!=null)
			{
				((MDIChild)ActiveMdiChild).richTextBox1.Paste();
				this.menuItem18.Enabled=true;
			}
			else
			{
				this.menuItem18.Enabled=false;
			}
		}

		private void MDIEditor_Closing(object sender, System.ComponentModel.CancelEventArgs e)
		{
//			if(MessageBox.Show("要关闭窗体吗?","提示",MessageBoxButtons.OKCancel,MessageBoxIcon.Information)==DialogResult.OK)
//			{
//
//			}
//			else
//			{
//				e.Cancel=true;
//			}
		}


		}
	}

⌨️ 快捷键说明

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