效果展示
主界面
文件操作
编辑操作
格式操作
查看操作
帮助操作
源码
FormBack.cs
using System ;
using System. Collections. Generic ;
using System. ComponentModel ;
using System. Data ;
using System. Drawing ;
using System. Linq ;
using System. Text ;
using System. Threading. Tasks ;
using System. Windows. Forms ;
namespace IntergratedDesign
{
public partial class FormBack : Form
{
public FormBack ( )
{
InitializeComponent ( ) ;
}
int documentCount = 1 ;
public FormRichText formRichText;
private void 新建NToolStripMenuItem_Click ( object sender, EventArgs e)
{
NewFile ( ) ;
}
private void 打开OToolStripMenuItem_Click ( object sender, EventArgs e)
{
OpenFile ( ) ;
}
private void 保存SToolStripMenuItem_Click ( object sender, EventArgs e)
{
if ( documentCount != 1 )
Save ( ) ;
}
private void 另存为AToolStripMenuItem_Click ( object sender, EventArgs e)
{
SaveAs ( ) ;
}
private void 退出XToolStripMenuItem_Click ( object sender, EventArgs e)
{
Close ( ) ;
}
private void 撤销ZToolStripMenuItem_Click ( object sender, EventArgs e)
{
FormRichText formRichText = ( FormRichText) this . ActiveMdiChild;
formRichText. richTextBox1. Undo ( ) ;
}
private void 剪切TToolStripMenuItem_Click ( object sender, EventArgs e)
{
FormRichText formRichText = ( FormRichText) this . ActiveMdiChild;
formRichText. richTextBox1. Cut ( ) ;
}
private void 复制CToolStripMenuItem_Click ( object sender, EventArgs e)
{
FormRichText formRichText = ( FormRichText) this . ActiveMdiChild;
formRichText. richTextBox1. Copy ( ) ;
}
private void 粘贴PToolStripMenuItem_Click ( object sender, EventArgs e)
{
FormRichText formRichText = ( FormRichText) this . ActiveMdiChild;
formRichText. richTextBox1. Paste ( ) ;
}
private void 删除LToolStripMenuItem_Click ( object sender, EventArgs e)
{
FormRichText formRichText = ( FormRichText) this . ActiveMdiChild;
if ( formRichText. richTextBox1. SelectedText. Length > 0 )
{
formRichText. richTextBox1. SelectedText = "" ;
}
}
private void 查找FToolStripMenuItem_Click ( object sender, EventArgs e)
{
formRichText = ( FormRichText) this . ActiveMdiChild;
FormFind formFind = new FormFind ( formRichText) ;
formFind. Show ( ) ;
}
private void 替换RToolStripMenuItem_Click ( object sender, EventArgs e)
{
formRichText = ( FormRichText) this . ActiveMdiChild;
FormFind formFind = new FormFind ( formRichText) ;
formFind. Show ( ) ;
}
private void 全选AToolStripMenuItem_Click ( object sender, EventArgs e)
{
FormRichText formRichText = ( FormRichText) this . ActiveMdiChild;
formRichText. richTextBox1. SelectAll ( ) ;
}
private void 字体FToolStripMenuItem_Click ( object sender, EventArgs e)
{
formRichText = ( FormRichText) this . ActiveMdiChild;
FontDialog fontDialog = new FontDialog ( ) ;
if ( fontDialog. ShowDialog ( ) != DialogResult. Cancel)
{
formRichText. richTextBox1. SelectionFont = fontDialog. Font;
}
}
private void 字体颜色CToolStripMenuItem_Click ( object sender, EventArgs e)
{
formRichText = ( FormRichText) this . ActiveMdiChild;
ColorDialog colorDialog = new ColorDialog ( ) ;
if ( colorDialog. ShowDialog ( ) != DialogResult. Cancel)
{
formRichText. richTextBox1. SelectionColor = colorDialog. Color;
}
}
private void 层叠ToolStripMenuItem_Click ( object sender, EventArgs e)
{
this . LayoutMdi ( MdiLayout. Cascade) ;
}
private void 水平平铺ToolStripMenuItem_Click ( object sender, EventArgs e)
{
this . LayoutMdi ( MdiLayout. TileHorizontal) ;
}
private void 垂直平铺ToolStripMenuItem_Click ( object sender, EventArgs e)
{
this . LayoutMdi ( MdiLayout. TileVertical) ;
}
private void 帮助HToolStripMenuItem_Click ( object sender, EventArgs e)
{
MessageBox. Show ( "开发人:Spring_Bear\n开发时间:" + DateTime. Now. ToString ( "yyyy-MM-dd " ) , "帮助" ) ;
}
private void NewFile ( )
{
formRichText = new FormRichText ( ) ;
formRichText. MdiParent = this ;
formRichText. Text = "新建文档" + documentCount++ ;
formRichText. Show ( ) ;
formRichText. isSaved = false ;
}
private void OpenFile ( )
{
string str;
formRichText = new FormRichText ( ) ;
formRichText. MdiParent = this ;
openFileDialog1. Filter = "文本文件(*.txt)|*.txt|富文本 (*.rtf)|*.rtf|全部文件 (*.*|*.*" ;
if ( openFileDialog1. ShowDialog ( ) != DialogResult. Cancel)
{
str = openFileDialog1. FileName;
formRichText. Text = str;
MessageBox. Show ( str + "打开成功!" ) ;
formRichText. Show ( ) ;
formRichText. richTextBox1. LoadFile ( openFileDialog1. FileName, RichTextBoxStreamType. PlainText) ;
formRichText. isSaved = true ;
}
}
private void Save ( )
{
String str;
FormRichText formRichText = ( FormRichText) this . ActiveMdiChild;
if ( ! formRichText. isChanged)
{
MessageBox. Show ( "文本内容未修改!" ) ;
return ;
}
if ( formRichText. isSaved)
{
formRichText = ( FormRichText) this . ActiveMdiChild;
str = formRichText. Text. Trim ( ) ;
formRichText. richTextBox1. SaveFile ( str, RichTextBoxStreamType. PlainText) ;
formRichText. isChanged = false ;
}
else
{
SaveAs ( ) ;
}
}
private void SaveAs ( )
{
string str;
formRichText = ( FormRichText) this . ActiveMdiChild;
saveFileDialog1. DefaultExt = "txt" ;
saveFileDialog1. Filter = "文本文件(*.txt)|*.txt|全部文件(*.*)|*.*" ;
if ( saveFileDialog1. ShowDialog ( this ) == DialogResult. OK)
{
str = saveFileDialog1. FileName;
MessageBox. Show ( str) ;
if ( str!= "" )
{
formRichText. richTextBox1. SaveFile ( str, RichTextBoxStreamType. PlainText) ;
formRichText. isSaved = true ;
formRichText. isChanged = false ;
}
else
{
MessageBox. Show ( "请输入文件名!" , "提示" , MessageBoxButtons. OK, MessageBoxIcon. Exclamation) ;
}
}
}
private void FormBack_Load ( object sender, EventArgs e)
{
this . timer1. Interval = 1000 ;
this . timer1. Start ( ) ;
}
private void timer1_Tick_1 ( object sender, EventArgs e)
{
this . toolStripStatusLabel1. Text = "系统当前时间:" + DateTime. Now. ToString ( "yyyy-MM-dd hh:mm:ss" ) ;
}
private void 时间日期DToolStripMenuItem_Click ( object sender, EventArgs e)
{
MessageBox. Show ( "系统当前时间为:" + DateTime. Now. ToString ( "yyyy-MM-dd hh:mm:ss" ) , "实时时间" ) ;
}
}
}
FormBack.Designer.cs
namespace IntergratedDesign
{
partial class FormBack
{
private System. ComponentModel. IContainer components = null ;
protected override void Dispose ( bool disposing)
{
if ( disposing && ( components != null ) )
{
components. Dispose ( ) ;
}
base . Dispose ( disposing) ;
}
#region Windows Form Designer generated code
private void InitializeComponent ( )
{
this . components = new System. ComponentModel. Container ( ) ;
System. ComponentModel. ComponentResourceManager resources = new System. ComponentModel. ComponentResourceManager ( typeof ( FormBack ) ) ;
this . menuStrip1 = new System. Windows. Forms. MenuStrip ( ) ;
this . 文件NToolStripMenuItem = new System. Windows. Forms. ToolStripMenuItem ( ) ;
this . 新建NToolStripMenuItem = new System. Windows. Forms. ToolStripMenuItem ( ) ;
this . 打开OToolStripMenuItem = new System. Windows. Forms. ToolStripMenuItem ( ) ;
this . 保存SToolStripMenuItem = new System. Windows. Forms. ToolStripMenuItem ( ) ;
this . 另存为AToolStripMenuItem = new System. Windows. Forms. ToolStripMenuItem ( ) ;
this . toolStripSeparator1 = new System. Windows. Forms. ToolStripSeparator ( ) ;
this . 打印PToolStripMenuItem = new System. Windows. Forms. ToolStripMenuItem ( ) ;
this . toolStripSeparator3 = new System. Windows. Forms. ToolStripSeparator ( ) ;
this . 退出XToolStripMenuItem = new System. Windows. Forms. ToolStripMenuItem ( ) ;
this . 编辑EToolStripMenuItem = new System. Windows. Forms. ToolStripMenuItem ( ) ;
this . 撤销ZToolStripMenuItem = new System. Windows. Forms. ToolStripMenuItem ( ) ;
this . toolStripSeparator4 = new System. Windows. Forms. ToolStripSeparator ( ) ;
this . 剪切TToolStripMenuItem = new System. Windows. Forms. ToolStripMenuItem ( ) ;
this . 复制CToolStripMenuItem = new System. Windows. Forms. ToolStripMenuItem ( ) ;
this . 粘贴PToolStripMenuItem = new System. Windows. Forms. ToolStripMenuItem ( ) ;
this . 删除LToolStripMenuItem = new System. Windows. Forms. ToolStripMenuItem ( ) ;
this . toolStripSeparator5 = new System. Windows. Forms. ToolStripSeparator ( ) ;
this . 查找FToolStripMenuItem = new System. Windows. Forms. ToolStripMenuItem ( ) ;
this . 替换RToolStripMenuItem = new System. Windows. Forms. ToolStripMenuItem ( ) ;
this . toolStripSeparator6 = new System. Windows. Forms. ToolStripSeparator ( ) ;
this . 全选AToolStripMenuItem = new System. Windows. Forms. ToolStripMenuItem ( ) ;
this . 时间日期DToolStripMenuItem = new System. Windows. Forms. ToolStripMenuItem ( ) ;
this . 格式OToolStripMenuItem = new System. Windows. Forms. ToolStripMenuItem ( ) ;
this . 自动换行WToolStripMenuItem = new System. Windows. Forms. ToolStripMenuItem ( ) ;
this . 字体FToolStripMenuItem = new System. Windows. Forms. ToolStripMenuItem ( ) ;
this . 字体颜色CToolStripMenuItem = new System. Windows. Forms. ToolStripMenuItem ( ) ;
this . 查看VToolStripMenuItem = new System. Windows. Forms. ToolStripMenuItem ( ) ;
this . 层叠ToolStripMenuItem = new System. Windows. Forms. ToolStripMenuItem ( ) ;
this . 水平平铺ToolStripMenuItem = new System. Windows. Forms. ToolStripMenuItem ( ) ;
this . 垂直平铺ToolStripMenuItem = new System. Windows. Forms. ToolStripMenuItem ( ) ;
this . 帮助HToolStripMenuItem = new System. Windows. Forms. ToolStripMenuItem ( ) ;
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 . printDocument1 = new System. Drawing. Printing. PrintDocument ( ) ;
this . printPreviewDialog1 = new System. Windows. Forms. PrintPreviewDialog ( ) ;
this . statusStrip1 = new System. Windows. Forms. StatusStrip ( ) ;
this . toolStripStatusLabel1 = new System. Windows. Forms. ToolStripStatusLabel ( ) ;
this . timer1 = new System. Windows. Forms. Timer ( this . components) ;
this . toolStripSeparator2 = new System. Windows. Forms. ToolStripSeparator ( ) ;
this . menuStrip1. SuspendLayout ( ) ;
this . statusStrip1. SuspendLayout ( ) ;
this . SuspendLayout ( ) ;
this . menuStrip1. ImageScalingSize = new System. Drawing. Size ( 20 , 20 ) ;
this . menuStrip1. Items. AddRange ( new System. Windows. Forms. ToolStripItem[ ] {
this . 文件NToolStripMenuItem,
this . 编辑EToolStripMenuItem,
this . 格式OToolStripMenuItem,
this . 查看VToolStripMenuItem,
this . 帮助HToolStripMenuItem} ) ;
this . menuStrip1. Location = new System. Drawing. Point ( 0 , 0 ) ;
this . menuStrip1. Name = "menuStrip1" ;
this . menuStrip1. Size = new System. Drawing. Size ( 648 , 28 ) ;
this . menuStrip1. TabIndex = 1 ;
this . menuStrip1. Text = "menuStrip1" ;
this . 文件NToolStripMenuItem. DropDownItems. AddRange ( new System. Windows. Forms. ToolStripItem[ ] {
this . 新建NToolStripMenuItem,
this . 打开OToolStripMenuItem,
this . 保存SToolStripMenuItem,
this . 另存为AToolStripMenuItem,
this . toolStripSeparator1,
this . 打印PToolStripMenuItem,
this . toolStripSeparator3,
this . 退出XToolStripMenuItem} ) ;
this . 文件NToolStripMenuItem. Name = "文件NToolStripMenuItem" ;
this . 文件NToolStripMenuItem. Size = new System. Drawing. Size ( 73 , 24 ) ;
this . 文件NToolStripMenuItem. Text = "文件(&N)" ;
this . 新建NToolStripMenuItem. Name = "新建NToolStripMenuItem" ;
this . 新建NToolStripMenuItem. ShortcutKeys = ( ( System. Windows. Forms. Keys) ( ( System. Windows. Forms. Keys. Control | System. Windows. Forms. Keys. N) ) ) ;
this . 新建NToolStripMenuItem. Size = new System. Drawing. Size ( 194 , 26 ) ;
this . 新建NToolStripMenuItem. Text = "新建(&N)" ;
this . 新建NToolStripMenuItem. Click += new System. EventHandler ( this . 新建NToolStripMenuItem_Click) ;
this . 打开OToolStripMenuItem. Name = "打开OToolStripMenuItem" ;
this . 打开OToolStripMenuItem. ShortcutKeys = ( ( System. Windows. Forms. Keys) ( ( System. Windows. Forms. Keys. Control | System. Windows. Forms. Keys. O) ) ) ;
this . 打开OToolStripMenuItem. Size = new System. Drawing. Size ( 194 , 26 ) ;
this . 打开OToolStripMenuItem. Text = "打开(&O)" ;
this . 打开OToolStripMenuItem. Click += new System. EventHandler ( this . 打开OToolStripMenuItem_Click) ;
this . 保存SToolStripMenuItem. Name = "保存SToolStripMenuItem" ;
this . 保存SToolStripMenuItem. ShortcutKeys = ( ( System. Windows. Forms. Keys) ( ( System. Windows. Forms. Keys. Control | System. Windows. Forms. Keys. S) ) ) ;
this . 保存SToolStripMenuItem. Size = new System. Drawing. Size ( 194 , 26 ) ;
this . 保存SToolStripMenuItem. Text = "保存(&S)" ;
this . 保存SToolStripMenuItem. Click += new System. EventHandler ( this . 保存SToolStripMenuItem_Click) ;
this . 另存为AToolStripMenuItem. Name = "另存为AToolStripMenuItem" ;
this . 另存为AToolStripMenuItem. Size = new System. Drawing. Size ( 194 , 26 ) ;
this . 另存为AToolStripMenuItem. Text = "另存为(&A)" ;
this . 另存为AToolStripMenuItem. Click += new System. EventHandler ( this . 另存为AToolStripMenuItem_Click) ;
this . toolStripSeparator1. Name = "toolStripSeparator1" ;
this . toolStripSeparator1. Size = new System. Drawing. Size ( 191 , 6 ) ;
this . 打印PToolStripMenuItem. Name = "打印PToolStripMenuItem" ;
this . 打印PToolStripMenuItem. Size = new System. Drawing. Size ( 194 , 26 ) ;
this . 打印PToolStripMenuItem. Text = "打印(&P)" ;
this . toolStripSeparator3. Name = "toolStripSeparator3" ;
this . toolStripSeparator3. Size = new System. Drawing. Size ( 191 , 6 ) ;
this . 退出XToolStripMenuItem. Name = "退出XToolStripMenuItem" ;
this . 退出XToolStripMenuItem. Size = new System. Drawing. Size ( 194 , 26 ) ;
this . 退出XToolStripMenuItem. Text = "退出(&X)" ;
this . 退出XToolStripMenuItem. Click += new System. EventHandler ( this . 退出XToolStripMenuItem_Click) ;
this . 编辑EToolStripMenuItem. DropDownItems. AddRange ( new System. Windows. Forms. ToolStripItem[ ] {
this . 撤销ZToolStripMenuItem,
this . toolStripSeparator4,
this . 剪切TToolStripMenuItem,
this . 复制CToolStripMenuItem,
this . 粘贴PToolStripMenuItem,
this . 删除LToolStripMenuItem,
this . toolStripSeparator5,
this . 全选AToolStripMenuItem,
this . toolStripSeparator2,
this . 查找FToolStripMenuItem,
this . 替换RToolStripMenuItem,
this . toolStripSeparator6,
this . 时间日期DToolStripMenuItem} ) ;
this . 编辑EToolStripMenuItem. Name = "编辑EToolStripMenuItem" ;
this . 编辑EToolStripMenuItem. Size = new System. Drawing. Size ( 69 , 24 ) ;
this . 编辑EToolStripMenuItem. Text = "编辑(&E)" ;
this . 撤销ZToolStripMenuItem. Name = "撤销ZToolStripMenuItem" ;
this . 撤销ZToolStripMenuItem. ShortcutKeys = ( ( System. Windows. Forms. Keys) ( ( System. Windows. Forms. Keys. Control | System. Windows. Forms. Keys. Z) ) ) ;
this . 撤销ZToolStripMenuItem. Size = new System. Drawing. Size ( 197 , 26 ) ;
this . 撤销ZToolStripMenuItem. Text = "撤销(&U)" ;
this . 撤销ZToolStripMenuItem. Click += new System. EventHandler ( this . 撤销ZToolStripMenuItem_Click) ;
this . toolStripSeparator4. Name = "toolStripSeparator4" ;
this . toolStripSeparator4. Size = new System. Drawing. Size ( 194 , 6 ) ;
this . 剪切TToolStripMenuItem. Name = "剪切TToolStripMenuItem" ;
this . 剪切TToolStripMenuItem. ShortcutKeys = ( ( System. Windows. Forms. Keys) ( ( System. Windows. Forms. Keys. Control | System. Windows. Forms. Keys. X) ) ) ;
this . 剪切TToolStripMenuItem. Size = new System. Drawing. Size ( 197 , 26 ) ;
this . 剪切TToolStripMenuItem. Text = "剪切(&T)" ;
this . 剪切TToolStripMenuItem. Click += new System. EventHandler ( this . 剪切TToolStripMenuItem_Click) ;
this . 复制CToolStripMenuItem. Name = "复制CToolStripMenuItem" ;
this . 复制CToolStripMenuItem. ShortcutKeys = ( ( System. Windows. Forms. Keys) ( ( System. Windows. Forms. Keys. Control | System. Windows. Forms. Keys. C) ) ) ;
this . 复制CToolStripMenuItem. Size = new System. Drawing. Size ( 197 , 26 ) ;
this . 复制CToolStripMenuItem. Text = "复制(&C)" ;
this . 复制CToolStripMenuItem. Click += new System. EventHandler ( this . 复制CToolStripMenuItem_Click) ;
this . 粘贴PToolStripMenuItem. Name = "粘贴PToolStripMenuItem" ;
this . 粘贴PToolStripMenuItem. ShortcutKeys = ( ( System. Windows. Forms. Keys) ( ( System. Windows. Forms. Keys. Control | System. Windows. Forms. Keys. V) ) ) ;
this . 粘贴PToolStripMenuItem. Size = new System. Drawing. Size ( 197 , 26 ) ;
this . 粘贴PToolStripMenuItem. Text = "粘贴(&P)" ;
this . 粘贴PToolStripMenuItem. Click += new System. EventHandler ( this . 粘贴PToolStripMenuItem_Click) ;
this . 删除LToolStripMenuItem. Name = "删除LToolStripMenuItem" ;
this . 删除LToolStripMenuItem. ShortcutKeys = System. Windows. Forms. Keys. Delete;
this . 删除LToolStripMenuItem. Size = new System. Drawing. Size ( 197 , 26 ) ;
this . 删除LToolStripMenuItem. Text = "删除(&L)" ;
this . 删除LToolStripMenuItem. Click += new System. EventHandler ( this . 删除LToolStripMenuItem_Click) ;
this . toolStripSeparator5. Name = "toolStripSeparator5" ;
this . toolStripSeparator5. Size = new System. Drawing. Size ( 194 , 6 ) ;
this . 查找FToolStripMenuItem. Name = "查找FToolStripMenuItem" ;
this . 查找FToolStripMenuItem. ShortcutKeys = ( ( System. Windows. Forms. Keys) ( ( System. Windows. Forms. Keys. Control | System. Windows. Forms. Keys. F) ) ) ;
this . 查找FToolStripMenuItem. Size = new System. Drawing. Size ( 197 , 26 ) ;
this . 查找FToolStripMenuItem. Text = "查找(&F)" ;
this . 查找FToolStripMenuItem. Click += new System. EventHandler ( this . 查找FToolStripMenuItem_Click) ;
this . 替换RToolStripMenuItem. Name = "替换RToolStripMenuItem" ;
this . 替换RToolStripMenuItem. ShortcutKeys = ( ( System. Windows. Forms. Keys) ( ( System. Windows. Forms. Keys. Control | System. Windows. Forms. Keys. H) ) ) ;
this . 替换RToolStripMenuItem. Size = new System. Drawing. Size ( 197 , 26 ) ;
this . 替换RToolStripMenuItem. Text = "替换(&R)" ;
this . 替换RToolStripMenuItem. Click += new System. EventHandler ( this . 替换RToolStripMenuItem_Click) ;
this . toolStripSeparator6. Name = "toolStripSeparator6" ;
this . toolStripSeparator6. Size = new System. Drawing. Size ( 194 , 6 ) ;
this . 全选AToolStripMenuItem. Name = "全选AToolStripMenuItem" ;
this . 全选AToolStripMenuItem. ShortcutKeys = ( ( System. Windows. Forms. Keys) ( ( System. Windows. Forms. Keys. Control | System. Windows. Forms. Keys. A) ) ) ;
this . 全选AToolStripMenuItem. Size = new System. Drawing. Size ( 197 , 26 ) ;
this . 全选AToolStripMenuItem. Text = "全选(&A)" ;
this . 全选AToolStripMenuItem. Click += new System. EventHandler ( this . 全选AToolStripMenuItem_Click) ;
this . 时间日期DToolStripMenuItem. Name = "时间日期DToolStripMenuItem" ;
this . 时间日期DToolStripMenuItem. ShortcutKeys = System. Windows. Forms. Keys. F5;
this . 时间日期DToolStripMenuItem. Size = new System. Drawing. Size ( 197 , 26 ) ;
this . 时间日期DToolStripMenuItem. Text = "时间/日期(&D)" ;
this . 时间日期DToolStripMenuItem. Click += new System. EventHandler ( this . 时间日期DToolStripMenuItem_Click) ;
this . 格式OToolStripMenuItem. DropDownItems. AddRange ( new System. Windows. Forms. ToolStripItem[ ] {
this . 自动换行WToolStripMenuItem,
this . 字体FToolStripMenuItem,
this . 字体颜色CToolStripMenuItem} ) ;
this . 格式OToolStripMenuItem. Name = "格式OToolStripMenuItem" ;
this . 格式OToolStripMenuItem. Size = new System. Drawing. Size ( 73 , 24 ) ;
this . 格式OToolStripMenuItem. Text = "格式(&O)" ;
this . 自动换行WToolStripMenuItem. Name = "自动换行WToolStripMenuItem" ;
this . 自动换行WToolStripMenuItem. Size = new System. Drawing. Size ( 169 , 26 ) ;
this . 自动换行WToolStripMenuItem. Text = "自动换行(&W)" ;
this . 字体FToolStripMenuItem. Name = "字体FToolStripMenuItem" ;
this . 字体FToolStripMenuItem. Size = new System. Drawing. Size ( 169 , 26 ) ;
this . 字体FToolStripMenuItem. Text = "字体大小(&F)" ;
this . 字体FToolStripMenuItem. Click += new System. EventHandler ( this . 字体FToolStripMenuItem_Click) ;
this . 字体颜色CToolStripMenuItem. Name = "字体颜色CToolStripMenuItem" ;
this . 字体颜色CToolStripMenuItem. Size = new System. Drawing. Size ( 169 , 26 ) ;
this . 字体颜色CToolStripMenuItem. Text = "字体颜色(&C)" ;
this . 字体颜色CToolStripMenuItem. Click += new System. EventHandler ( this . 字体颜色CToolStripMenuItem_Click) ;
this . 查看VToolStripMenuItem. DropDownItems. AddRange ( new System. Windows. Forms. ToolStripItem[ ] {
this . 层叠ToolStripMenuItem,
this . 水平平铺ToolStripMenuItem,
this . 垂直平铺ToolStripMenuItem} ) ;
this . 查看VToolStripMenuItem. Name = "查看VToolStripMenuItem" ;
this . 查看VToolStripMenuItem. Size = new System. Drawing. Size ( 71 , 24 ) ;
this . 查看VToolStripMenuItem. Text = "查看(&V)" ;
this . 层叠ToolStripMenuItem. Name = "层叠ToolStripMenuItem" ;
this . 层叠ToolStripMenuItem. Size = new System. Drawing. Size ( 144 , 26 ) ;
this . 层叠ToolStripMenuItem. Text = "层叠" ;
this . 层叠ToolStripMenuItem. Click += new System. EventHandler ( this . 层叠ToolStripMenuItem_Click) ;
this . 水平平铺ToolStripMenuItem. Name = "水平平铺ToolStripMenuItem" ;
this . 水平平铺ToolStripMenuItem. Size = new System. Drawing. Size ( 144 , 26 ) ;
this . 水平平铺ToolStripMenuItem. Text = "水平平铺" ;
this . 水平平铺ToolStripMenuItem. Click += new System. EventHandler ( this . 水平平铺ToolStripMenuItem_Click) ;
this . 垂直平铺ToolStripMenuItem. Name = "垂直平铺ToolStripMenuItem" ;
this . 垂直平铺ToolStripMenuItem. Size = new System. Drawing. Size ( 144 , 26 ) ;
this . 垂直平铺ToolStripMenuItem. Text = "垂直平铺" ;
this . 垂直平铺ToolStripMenuItem. Click += new System. EventHandler ( this . 垂直平铺ToolStripMenuItem_Click) ;
this . 帮助HToolStripMenuItem. Name = "帮助HToolStripMenuItem" ;
this . 帮助HToolStripMenuItem. Size = new System. Drawing. Size ( 73 , 24 ) ;
this . 帮助HToolStripMenuItem. Text = "帮助(&H)" ;
this . 帮助HToolStripMenuItem. Click += new System. EventHandler ( this . 帮助HToolStripMenuItem_Click) ;
this . openFileDialog1. FileName = "openFileDialog1" ;
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. Name = "printPreviewDialog1" ;
this . printPreviewDialog1. Visible = false ;
this . statusStrip1. ImageScalingSize = new System. Drawing. Size ( 20 , 20 ) ;
this . statusStrip1. Items. AddRange ( new System. Windows. Forms. ToolStripItem[ ] {
this . toolStripStatusLabel1} ) ;
this . statusStrip1. Location = new System. Drawing. Point ( 0 , 594 ) ;
this . statusStrip1. Name = "statusStrip1" ;
this . statusStrip1. Size = new System. Drawing. Size ( 648 , 25 ) ;
this . statusStrip1. TabIndex = 3 ;
this . statusStrip1. Text = "statusStrip1" ;
this . toolStripStatusLabel1. Name = "toolStripStatusLabel1" ;
this . toolStripStatusLabel1. Size = new System. Drawing. Size ( 129 , 20 ) ;
this . toolStripStatusLabel1. Text = "系统当前时间为:" ;
this . timer1. Tick += new System. EventHandler ( this . timer1_Tick_1) ;
this . toolStripSeparator2. Name = "toolStripSeparator2" ;
this . toolStripSeparator2. Size = new System. Drawing. Size ( 194 , 6 ) ;
this . AutoScaleDimensions = new System. Drawing. SizeF ( 8F , 15F ) ;
this . AutoScaleMode = System. Windows. Forms. AutoScaleMode. Font;
this . ClientSize = new System. Drawing. Size ( 648 , 619 ) ;
this . Controls. Add ( this . statusStrip1) ;
this . Controls. Add ( this . menuStrip1) ;
this . IsMdiContainer = true ;
this . MainMenuStrip = this . menuStrip1;
this . Name = "FormBack" ;
this . Text = "文本编辑器" ;
this . Load += new System. EventHandler ( this . FormBack_Load) ;
this . menuStrip1. ResumeLayout ( false ) ;
this . menuStrip1. PerformLayout ( ) ;
this . statusStrip1. ResumeLayout ( false ) ;
this . statusStrip1. PerformLayout ( ) ;
this . ResumeLayout ( false ) ;
this . PerformLayout ( ) ;
}
#endregion
private System. Windows. Forms. MenuStrip menuStrip1;
private System. Windows. Forms. OpenFileDialog openFileDialog1;
private System. Windows. Forms. SaveFileDialog saveFileDialog1;
private System. Windows. Forms. FontDialog fontDialog1;
private System. Windows. Forms. ColorDialog colorDialog1;
private System. Drawing. Printing. PrintDocument printDocument1;
private System. Windows. Forms. PrintPreviewDialog printPreviewDialog1;
private System. Windows. Forms. ToolStripMenuItem 文件NToolStripMenuItem;
private System. Windows. Forms. ToolStripMenuItem 新建NToolStripMenuItem;
private System. Windows. Forms. ToolStripMenuItem 打开OToolStripMenuItem;
private System. Windows. Forms. ToolStripMenuItem 保存SToolStripMenuItem;
private System. Windows. Forms. ToolStripMenuItem 另存为AToolStripMenuItem;
private System. Windows. Forms. ToolStripSeparator toolStripSeparator1;
private System. Windows. Forms. ToolStripMenuItem 打印PToolStripMenuItem;
private System. Windows. Forms. ToolStripSeparator toolStripSeparator3;
private System. Windows. Forms. ToolStripMenuItem 退出XToolStripMenuItem;
private System. Windows. Forms. ToolStripMenuItem 编辑EToolStripMenuItem;
private System. Windows. Forms. ToolStripMenuItem 撤销ZToolStripMenuItem;
private System. Windows. Forms. ToolStripSeparator toolStripSeparator4;
private System. Windows. Forms. ToolStripMenuItem 剪切TToolStripMenuItem;
private System. Windows. Forms. ToolStripMenuItem 复制CToolStripMenuItem;
private System. Windows. Forms. ToolStripMenuItem 粘贴PToolStripMenuItem;
private System. Windows. Forms. ToolStripMenuItem 删除LToolStripMenuItem;
private System. Windows. Forms. ToolStripSeparator toolStripSeparator5;
private System. Windows. Forms. ToolStripMenuItem 查找FToolStripMenuItem;
private System. Windows. Forms. ToolStripMenuItem 替换RToolStripMenuItem;
private System. Windows. Forms. ToolStripSeparator toolStripSeparator6;
private System. Windows. Forms. ToolStripMenuItem 全选AToolStripMenuItem;
private System. Windows. Forms. ToolStripMenuItem 时间日期DToolStripMenuItem;
private System. Windows. Forms. ToolStripMenuItem 格式OToolStripMenuItem;
private System. Windows. Forms. ToolStripMenuItem 自动换行WToolStripMenuItem;
private System. Windows. Forms. ToolStripMenuItem 字体FToolStripMenuItem;
private System. Windows. Forms. ToolStripMenuItem 字体颜色CToolStripMenuItem;
private System. Windows. Forms. ToolStripMenuItem 查看VToolStripMenuItem;
private System. Windows. Forms. ToolStripMenuItem 帮助HToolStripMenuItem;
private System. Windows. Forms. ToolStripMenuItem 层叠ToolStripMenuItem;
private System. Windows. Forms. ToolStripMenuItem 水平平铺ToolStripMenuItem;
private System. Windows. Forms. ToolStripMenuItem 垂直平铺ToolStripMenuItem;
private System. Windows. Forms. StatusStrip statusStrip1;
private System. Windows. Forms. ToolStripStatusLabel toolStripStatusLabel1;
private System. Windows. Forms. Timer timer1;
private System. Windows. Forms. ToolStripSeparator toolStripSeparator2;
}
}
FormFind.cs
using System ;
using System. Collections. Generic ;
using System. ComponentModel ;
using System. Data ;
using System. Drawing ;
using System. Linq ;
using System. Text ;
using System. Threading. Tasks ;
using System. Windows. Forms ;
namespace IntergratedDesign
{
public partial class FormFind : Form
{
FormRichText parentForm;
private String strSearch = "" ;
private String strReplace = "" ;
private int searchPos = 0 , lastSearchPos = 0 ;
private bool find;
public FormFind ( FormRichText parent)
{
this . parentForm = parent;
InitializeComponent ( ) ;
}
private void button1_Click ( object sender, EventArgs e)
{
SearchText ( ) ;
}
private void button2_Click ( object sender, EventArgs e)
{
ReplaceText ( ) ;
}
private bool SearchText ( )
{
strSearch = findText. Text;
strReplace = replaceText. Text;
if ( checkCase. Checked)
{
if ( radioDown. Checked)
{
searchPos = parentForm. richTextBox1. Find ( strSearch, searchPos, parentForm. richTextBox1. Text. Length, RichTextBoxFinds. MatchCase) ;
}
else
{
this . searchPos = this . parentForm. richTextBox1. Find ( this . strSearch, 0 , searchPos, RichTextBoxFinds. MatchCase | RichTextBoxFinds. Reverse) ;
}
}
else
{
if ( this . radioDown. Checked)
{
this . searchPos = this . parentForm. richTextBox1. Find ( this . strSearch, searchPos, this . parentForm. richTextBox1. Text. Length, RichTextBoxFinds. None) ;
}
else
{
this . searchPos = this . parentForm. richTextBox1. Find ( this . strSearch, 0 , searchPos, RichTextBoxFinds. Reverse) ;
}
}
if ( this . searchPos < 0 )
{
this . searchPos = this . lastSearchPos;
find = false ;
}
else
{
if ( this . radioDown. Checked)
{
this . searchPos += this . strSearch. Length;
}
else
{
this . searchPos -= this . strSearch. Length;
}
}
this . lastSearchPos = this . searchPos;
return find;
}
private void FormFind_Load ( object sender, EventArgs e)
{
}
private void ReplaceText ( )
{
this . strSearch = this . findText. Text;
this . strReplace = this . replaceText. Text;
if ( ! SearchText ( ) )
{
if ( this . parentForm. richTextBox1. SelectedText. Length > 0 )
{
this . parentForm. richTextBox1. SelectedText = this . strReplace;
}
}
}
}
}
FormFind.Designer.cs
namespace IntergratedDesign
{
partial class FormFind
{
private System. ComponentModel. IContainer components = null ;
protected override void Dispose ( bool disposing)
{
if ( disposing && ( components != null ) )
{
components. Dispose ( ) ;
}
base . Dispose ( disposing) ;
}
#region Windows Form Designer generated code
private void InitializeComponent ( )
{
this . label1 = new System. Windows. Forms. Label ( ) ;
this . label2 = new System. Windows. Forms. Label ( ) ;
this . checkCase = new System. Windows. Forms. CheckBox ( ) ;
this . button1 = new System. Windows. Forms. Button ( ) ;
this . button2 = new System. Windows. Forms. Button ( ) ;
this . radioUp = new System. Windows. Forms. RadioButton ( ) ;
this . radioDown = new System. Windows. Forms. RadioButton ( ) ;
this . findText = new System. Windows. Forms. TextBox ( ) ;
this . replaceText = new System. Windows. Forms. TextBox ( ) ;
this . SuspendLayout ( ) ;
this . label1. AutoSize = true ;
this . label1. Location = new System. Drawing. Point ( 32 , 36 ) ;
this . label1. Name = "label1" ;
this . label1. Size = new System. Drawing. Size ( 67 , 15 ) ;
this . label1. TabIndex = 0 ;
this . label1. Text = "查找内容" ;
this . label2. AutoSize = true ;
this . label2. Location = new System. Drawing. Point ( 32 , 87 ) ;
this . label2. Name = "label2" ;
this . label2. Size = new System. Drawing. Size ( 52 , 15 ) ;
this . label2. TabIndex = 1 ;
this . label2. Text = "替换为" ;
this . checkCase. AutoSize = true ;
this . checkCase. Location = new System. Drawing. Point ( 35 , 136 ) ;
this . checkCase. Name = "checkCase" ;
this . checkCase. Size = new System. Drawing. Size ( 104 , 19 ) ;
this . checkCase. TabIndex = 2 ;
this . checkCase. Text = "区分大小写" ;
this . checkCase. UseVisualStyleBackColor = true ;
this . button1. Location = new System. Drawing. Point ( 337 , 27 ) ;
this . button1. Name = "button1" ;
this . button1. Size = new System. Drawing. Size ( 50 , 31 ) ;
this . button1. TabIndex = 3 ;
this . button1. Text = "查找" ;
this . button1. UseVisualStyleBackColor = true ;
this . button1. Click += new System. EventHandler ( this . button1_Click) ;
this . button2. Location = new System. Drawing. Point ( 337 , 78 ) ;
this . button2. Name = "button2" ;
this . button2. Size = new System. Drawing. Size ( 50 , 31 ) ;
this . button2. TabIndex = 4 ;
this . button2. Text = "替换" ;
this . button2. UseVisualStyleBackColor = true ;
this . button2. Click += new System. EventHandler ( this . button2_Click) ;
this . radioUp. AutoSize = true ;
this . radioUp. Location = new System. Drawing. Point ( 157 , 135 ) ;
this . radioUp. Name = "radioUp" ;
this . radioUp. Size = new System. Drawing. Size ( 58 , 19 ) ;
this . radioUp. TabIndex = 5 ;
this . radioUp. Text = "向上" ;
this . radioUp. UseVisualStyleBackColor = true ;
this . radioDown. AutoSize = true ;
this . radioDown. Checked = true ;
this . radioDown. Location = new System. Drawing. Point ( 239 , 136 ) ;
this . radioDown. Name = "radioDown" ;
this . radioDown. Size = new System. Drawing. Size ( 58 , 19 ) ;
this . radioDown. TabIndex = 6 ;
this . radioDown. TabStop = true ;
this . radioDown. Text = "向下" ;
this . radioDown. UseVisualStyleBackColor = true ;
this . findText. Location = new System. Drawing. Point ( 105 , 31 ) ;
this . findText. Name = "findText" ;
this . findText. Size = new System. Drawing. Size ( 192 , 25 ) ;
this . findText. TabIndex = 7 ;
this . replaceText. Location = new System. Drawing. Point ( 105 , 81 ) ;
this . replaceText. Name = "replaceText" ;
this . replaceText. Size = new System. Drawing. Size ( 192 , 25 ) ;
this . replaceText. TabIndex = 8 ;
this . AutoScaleDimensions = new System. Drawing. SizeF ( 8F , 15F ) ;
this . AutoScaleMode = System. Windows. Forms. AutoScaleMode. Font;
this . ClientSize = new System. Drawing. Size ( 426 , 175 ) ;
this . Controls. Add ( this . replaceText) ;
this . Controls. Add ( this . findText) ;
this . Controls. Add ( this . radioDown) ;
this . Controls. Add ( this . radioUp) ;
this . Controls. Add ( this . button2) ;
this . Controls. Add ( this . button1) ;
this . Controls. Add ( this . checkCase) ;
this . Controls. Add ( this . label2) ;
this . Controls. Add ( this . label1) ;
this . Name = "FormFind" ;
this . Text = "查找和替换" ;
this . Load += new System. EventHandler ( this . FormFind_Load) ;
this . ResumeLayout ( false ) ;
this . PerformLayout ( ) ;
}
#endregion
private System. Windows. Forms. Label label1;
private System. Windows. Forms. Label label2;
private System. Windows. Forms. CheckBox checkCase;
private System. Windows. Forms. Button button1;
private System. Windows. Forms. Button button2;
private System. Windows. Forms. RadioButton radioUp;
private System. Windows. Forms. RadioButton radioDown;
private System. Windows. Forms. TextBox findText;
private System. Windows. Forms. TextBox replaceText;
}
}
FormRichText.cs
using System ;
using System. Collections. Generic ;
using System. ComponentModel ;
using System. Data ;
using System. Drawing ;
using System. Linq ;
using System. Text ;
using System. Threading. Tasks ;
using System. Windows. Forms ;
namespace IntergratedDesign
{
public partial class FormRichText : Form
{
public FormRichText ( )
{
InitializeComponent ( ) ;
}
public bool isChanged = true ;
public bool isSaved;
private void FormRichText_Load ( object sender, EventArgs e)
{
}
public Font SelectionFont {
get ; internal set ; }
internal void SaveFile ( string fileName, RichTextBoxStreamType plainText)
{
throw new NotImplementedException ( ) ;
}
private void richTextBox1_TextChanged ( object sender, EventArgs e)
{
isChanged = true ;
}
}
}
FormRichText.Designer.cs
namespace IntergratedDesign
{
partial class FormRichText
{
private System. ComponentModel. IContainer components = null ;
protected override void Dispose ( bool disposing)
{
if ( disposing && ( components != null ) )
{
components. Dispose ( ) ;
}
base . Dispose ( disposing) ;
}
#region Windows Form Designer generated code
private void InitializeComponent ( )
{
this . saveFileDialog1 = new System. Windows. Forms. SaveFileDialog ( ) ;
this . saveFileDialog2 = new System. Windows. Forms. SaveFileDialog ( ) ;
this . fontDialog1 = new System. Windows. Forms. FontDialog ( ) ;
this . richTextBox1 = new System. Windows. Forms. RichTextBox ( ) ;
this . SuspendLayout ( ) ;
this . richTextBox1. Dock = System. Windows. Forms. DockStyle. Fill;
this . richTextBox1. Location = new System. Drawing. Point ( 0 , 0 ) ;
this . richTextBox1. Name = "richTextBox1" ;
this . richTextBox1. Size = new System. Drawing. Size ( 537 , 397 ) ;
this . richTextBox1. TabIndex = 0 ;
this . richTextBox1. Text = "" ;
this . AutoScaleDimensions = new System. Drawing. SizeF ( 8F , 15F ) ;
this . AutoScaleMode = System. Windows. Forms. AutoScaleMode. Font;
this . ClientSize = new System. Drawing. Size ( 537 , 397 ) ;
this . Controls. Add ( this . richTextBox1) ;
this . Name = "FormRichText" ;
this . Text = "文本编辑" ;
this . Load += new System. EventHandler ( this . FormRichText_Load) ;
this . ResumeLayout ( false ) ;
}
#endregion
private System. Windows. Forms. SaveFileDialog saveFileDialog1;
private System. Windows. Forms. SaveFileDialog saveFileDialog2;
private System. Windows. Forms. FontDialog fontDialog1;
public System. Windows. Forms. RichTextBox richTextBox1;
}
}
Program.cs
using System ;
using System. Collections. Generic ;
using System. Linq ;
using System. Threading. Tasks ;
using System. Windows. Forms ;
namespace IntergratedDesign
{
static class Program
{
[ STAThread]
static void Main ( )
{
Application. EnableVisualStyles ( ) ;
Application. SetCompatibleTextRenderingDefault ( false ) ;
Application. Run ( new FormBack ( ) ) ;
}
}
}