资源描述:
《CNET容器菜单与工具栏对话框控件的练习.doc》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、姓名学号专业班级课程名称.NET程序设计实验名称容器、菜单与工具栏、对话框控件的练习实验日期同组人员指导教师得分一、实验内容设计一个简易的记事本软件,实现对文本文件的以下操作功能:(1)新建、打开、保存、另存为和退出文件;(2)编辑文件:包括复制、剪贴、粘帖、清除、撤销;(3)文件查看:包括是否显示工具栏和状态栏;(4)设置字体、颜色、自动换行;(5)利用快捷菜单编辑文件。二、界面(设计和运行状态的截图)简易记事本运行结果如图所示:三、代码usingSystem;usingSystem.Collections.Generic;usingSys
2、tem.ComponentModel;usingSystem.Data;filename=dialog.FileName;richTextBox1.SaveFile(filename,RichTextBoxStreamType.RichText);usingSystem.Drawing;usingSystem.Text;usingSystem.Windows.Forms;namespaceWindowsApplication1{publicpartialclassForm1:Form{privatevoidmnufile_new_Click(
3、objectsender,EventArgse){if(richTextBox1.Modified){if(MessageBox.Show("内容已修改,是否保存?","警告",MessageBoxButtons.OKCancel,MessageBoxIcon.Warning)==DialogResult.OK)mnufile_save_Click(sender,e);}richTextBox1.Clear();filename="";this.Text="简易记事本";}privatevoidmnufile_open_Click(objec
4、tsender,EventArgse){OpenFileDialogdialog=newOpenFileDialog();dialog.Filter="RTFfile(*.rtf)
5、*.rtf";dialog.FilterIndex=1;if(dialog.ShowDialog()==DialogResult.OK&&dialog.FileName!=""){filename=dialog.FileName;richTextBox1.LoadFile(filename,RichTextBoxStreamType.RichText);this.
6、Text="简易记事本-"+filename;}}privatevoidmnufile_save_Click(objectsender,EventArgse){if(filename==null
7、
8、filename=="")mnufile_saveas_Click(sender,e);else{richTextBox1.SaveFile(filename,RichTextBoxStreamType.RichText);richTextBox1.Modified=false;}}privatevoidmnufile_saveas_Click(o
9、bjectsender,EventArgse){SaveFileDialogdialog=newSaveFileDialog();dialog.Filter="RTFfile(*.rtf)
10、*.rtf";dialog.FilterIndex=1;if(dialog.ShowDialog()==DialogResult.OK&&dialog.FileName!=""){richTextBox1.Modified=false;this.Text="文字编辑器"+filename;}}privatevoidmnufile_exit_Click(ob
11、jectsender,EventArgse){this.Close();}privatevoidmnuedit_undo_Click(objectsender,EventArgse){if(richTextBox1.CanUndo)richTextBox1.Undo();}privatevoidmnuedit_copy_Click(objectsender,EventArgse){richTextBox1.Copy();}privatevoidmnuedit_cut_Click(objectsender,EventArgse){richTex
12、tBox1.Cut();}privatevoidmnuedit_paste_Click(objectsender,EventArgse){richTextBox1.