已阅读5页,还剩5页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
实验要求 编写一个能够显示多个文本文件的多文档程序 对多个文本文件进行不同操作 实现 不同的操作 如查找 替换 字体 颜色 多窗口排列操作等 程序运行时 实现打开文件 新建文件等操作 出现子窗口时 进行不同的操作 从 而实现 MDI 应用程序 实验内容 一 进行多窗体设计 父窗口程序代码 using System using System Collections Generic using System ComponentModel using System Data using System Drawing using System Text using System Windows Forms namespace WindowsApplication1 public partial class Form1 Form public Form1 InitializeComponent public int xinjian i private void 新建文件NToolStripMenuItem Click object sender EventArgs e i 0 Form2 child new Form2 child MdiParent this child Text 新建RTF文档 xinjian child Show private void 打开OToolStripMenuItem Click object sender EventArgs e Form2 child new Form2 i 1 openFileDialog1 FileName string file openFileDialog1 FileName openFileDialog1 Filter RTF rtf rtf openFileDialog1 FilterIndex 1 openFileDialog1 Title 打开文件 openFileDialog1 InitialDirectory Application StartupPath openFileDialog1 RestoreDirectory false openFileDialog1 ShowDialog file openFileDialog1 FileName if file child MdiParent this child MainMenuStrip Visible false child Show child Text file child richTextBox1 LoadFile file RichTextBoxStreamType RichText 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 层叠ToolStripMenuItem Click object sender EventArgs e this LayoutMdi MdiLayout Cascade private void 关闭所有子窗口ToolStripMenuItem Click object sender EventArgs e foreach Form childForm in MdiChildren childForm Close private void 退出XToolStripMenuItem Click object sender EventArgs e Application Exit 父窗体设计如图 子窗体程序代码 using System using System Collections Generic using System ComponentModel using System Data using System Drawing using System Text using System Windows Forms namespace WindowsApplication1 public partial class Form2 Form public Form2 InitializeComponent private void 字体ToolStripMenuItem Click object sender EventArgs e fontDialog1 ShowEffects true 显示设置下划线 删除线等的复选框 在弹出字体对话框前 把字体对话框的字体设置为选定文本的字体 fontDialog1 Font richTextBox1 SelectionFont if fontDialog1 ShowDialog DialogResult OK 弹出字体对话框且用户单击了 确定 按钮 richTextBox1 SelectionFont fontDialog1 Font 设置选中文本的字体 private void 颜色ToolStripMenuItem Click object sender EventArgs e colorDialog1 AllowFullOpen true 允许用户自定义颜色 colorDialog1 AnyColor true 显示基本色的全部颜色 在弹出颜色对话框前 把颜色对话框的颜色设置为选定文本的颜色 colorDialog1 Color richTextBox1 SelectionColor if colorDialog1 ShowDialog DialogResult OK richTextBox1 SelectionColor colorDialog1 Color private void 关闭ToolStripMenuItem1 Click object sender EventArgs e Form3 exitForm new Form3 根据Form3窗体类生成对象 if exitForm ShowDialog DialogResult OK 显示对话框并判断是否按了 确定 按钮 exitForm Close 退出对话框关闭 this Close 当前窗体关闭 Application Exit 应用程序关闭 private void 字体ToolStripMenuItem Click 1 object sender EventArgs e fontDialog1 ShowEffects true 显示设置下划线 删除线等的复选框 在弹出字体对话框前 把字体对话框的字体设置为选定文本的字体 fontDialog1 Font richTextBox1 SelectionFont if fontDialog1 ShowDialog DialogResult OK 弹出字体对话框且用户单击了 确定 按钮 richTextBox1 SelectionFont fontDialog1 Font 设置选中文本的字体 private void Form2 Load object sender EventArgs e private void 关闭ToolStripMenuItem1 Click 1 object sender EventArgs e Form3 exitForm new Form3 根据Form3窗体类生成对象 if exitForm ShowDialog DialogResult OK 显示对话框并判断是否按了 确定 按钮 exitForm Close 退出对话框关闭 this Close 当前窗体关闭 Application Exit 应用程序关闭 private void 保存ToolStripMenuItem Click object sender EventArgs e Form1 f1 Form1 this MdiParent if f1 i 1 string file saveFileDialog1 Filter RTF文件 rtf rtf saveFileDialog1 FilterIndex 1 saveFileDialog1 Title 保存文件 saveFileDialog1 InitialDirectory Application StartupPath saveFileDialog1 RestoreDirectory false saveFileDialog1 ShowDialog file saveFileDialog1 FileName if file if openFileDialog1 FilterIndex 1 richTextBox1 SaveFile file RichTextBoxStreamType RichText else string file file openFileDialog1 FileName richTextBox1 SaveFile file RichTextBoxStreamType RichText richTextBox1 Modified false MessageBox Show 文件已保存 保存 private void 关闭ToolStripMenuItem Click object sender EventArgs e Form3 saveForm new Form3 string file saveFileDialog1 Filter RTF rtf rtf saveFileDialog1 FilterIndex 1 saveFileDialog1 Title 另存文件 saveFileDialog1 InitialDirectory Application StartupPath saveFileDialog1 RestoreDirectory false saveFileDialog1 ShowDialog file saveFileDialog1 FileName if file if openFileDialog1 FilterIndex 1 richTextBox1 SaveFile file RichTextBoxStreamType RichText richTextBox1 Modified false MessageBox Show 文件已保存 保存 private void 查找ToolStripMenuItem Click object sender EventArgs e Form4 chazhao new Form4 chazhao s1 this richTextBox1 chazhao Show private void 替换ToolStripMenuItem Click object sender EventArgs e Form5 arep new Form5 arep s1 this richTextBox1 arep Show private void 白色ToolStripMenuItem Click object sender EventArgs e richTextBox1 BackColor Color White 白色ToolStripMenuItem Checked true 白色ToolStripMenuItem Checked false private void 蓝色ToolStripMenuItem Click object sender EventArgs e richTextBox1 BackColor Color Blue 蓝色ToolStripMenuItem Checked true 蓝色ToolStripMenuItem Checked false private void 红色ToolStripMenuItem Click object sender EventArgs e richTextBox1 BackColor Color Red 红色ToolStripMenuItem Checked true 红色ToolStripMenuItem Checked false private void 历史记录ToolStripMenuItem Click object sender EventArgs e 子窗体设计如图 再在子窗体上实现其它功能 如查找 单个替换 全部替换 关闭等功能 并实现父窗体和子窗体的菜单 合并 关闭页面程序代码 namespace WindowsApplication1 public partial class Form3 Form public Form3 InitializeComponent private void Form3 Load object sender EventArgs e 查找程序代码 namespace WindowsApplication1 public partial class Form4 Form public Form4 InitializeComponent public RichTextBox s1 public int start private void button1 Click object sender EventArgs e string str1 str1 textBox1 Text if str1 MessageBox Show 请确认查找内容 异常警示 else start s1 Find str1 start RichTextBoxFinds MatchCase if start 1 MessageBox Show 已经查到文档的结尾 结束查找 start 0 s1 Focus else start start str1 Length s1 Focus private void button2 Click object sender EventArgs e this Close private void Form4 Load object sender EventArgs e 查找界面 替换程序代码 namespace WindowsApplication1 public partial class Form5 Form public Form5 InitializeComponent public RichTextBox s1 public int start rep2 private void button1 Click object sender EventArgs e try string str1 str2 str1 textBox1 Text str2 textBox2 Text if str1 str2 MessageBox Show 请确认替换内容 异常警示 else start s1 Find str1 start RichTextBoxFinds Matc
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 阜阳六院护士考试试题及答案
- 法律知识考试题目及答案
- 钢材公司可行性研究报告
- 钻机市场发展现状调查及供需格局分析预测报告2025年
- 防火涂料检验报告2025
- 预制型橡胶跑道产业实施方案
- 高铁可行性研究报告
- 2020-2025年统计师之中级统计师工作实务押题练习试题B卷含答案
- 2020-2025年一级注册建筑师之建筑物理与建筑设备押题练习试题A卷含答案
- 2020-2025年检验类之临床医学检验技术中级通关提分题库(考点梳理)
- 2025上半年系统分析师综合知识考试真题及答案
- 行政领导学-形考任务三-国开-参考资料
- DB42∕T 2300.1-2024 农业生态产品生产技术规范 第1部分:通则
- 江西省南昌市2024-2025学年八年级上学期11月期中考试生物试卷(含答案)
- 道路交通安全法培训课件
- 2025年核技术利用辐射安全与防护考试(放射治疗)测试题及答案
- 低空经济:新质生产力的新赛道
- 大棚蔬菜合伙协议书模板
- 煤炭交易相关知识培训课件
- 数据安全与合规管理课件
- 2025年高级卫生专业技术资格考试(副高)老年医学(副高)试题及答案
评论
0/150
提交评论