您好,欢迎访问三七文档
当前位置:首页 > 商业/管理/HR > 销售管理 > CNET容器菜单与工具栏对话框控件的练习
姓名学号专业班级课程名称.NET程序设计实验名称容器、菜单与工具栏、对话框控件的练习实验日期同组人员指导教师得分一、实验内容设计一个简易的记事本软件,实现对文本文件的以下操作功能:(1)新建、打开、保存、另存为和退出文件;(2)编辑文件:包括复制、剪贴、粘帖、清除、撤销;(3)文件查看:包括是否显示工具栏和状态栏;(4)设置字体、颜色、自动换行;(5)利用快捷菜单编辑文件。二、界面(设计和运行状态的截图)简易记事本运行结果如图所示:三、代码usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;filename=dialog.FileName;richTextBox1.SaveFile(filename,RichTextBoxStreamType.RichText);usingSystem.Drawing;usingSystem.Text;usingSystem.Windows.Forms;namespaceWindowsApplication1{publicpartialclassForm1:Form{privatevoidmnufile_new_Click(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(objectsender,EventArgse){OpenFileDialogdialog=newOpenFileDialog();dialog.Filter=RTFfile(*.rtf)|*.rtf;dialog.FilterIndex=1;if(dialog.ShowDialog()==DialogResult.OK&&dialog.FileName!=){filename=dialog.FileName;richTextBox1.LoadFile(filename,RichTextBoxStreamType.RichText);this.Text=简易记事本-+filename;}}privatevoidmnufile_save_Click(objectsender,EventArgse){if(filename==null||filename==)mnufile_saveas_Click(sender,e);else{richTextBox1.SaveFile(filename,RichTextBoxStreamType.RichText);richTextBox1.Modified=false;}}privatevoidmnufile_saveas_Click(objectsender,EventArgse){SaveFileDialogdialog=newSaveFileDialog();dialog.Filter=RTFfile(*.rtf)|*.rtf;dialog.FilterIndex=1;if(dialog.ShowDialog()==DialogResult.OK&&dialog.FileName!=){richTextBox1.Modified=false;this.Text=文字编辑器+filename;}}privatevoidmnufile_exit_Click(objectsender,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){richTextBox1.Cut();}privatevoidmnuedit_paste_Click(objectsender,EventArgse){richTextBox1.Paste(DataFormats.GetFormat(DataFormats.Rtf));}privatevoidmnuedit_clear_Click(objectsender,EventArgse){richTextBox1.Clear();}privatevoidmnuview_tool_Click(objectsender,EventArgse){toolStrip1.Visible=!toolStrip1.Visible;}privatevoidmnuview_stat_Click(objectsender,EventArgse){statusStrip1.Visible=!statusStrip1.Visible;}privatevoidmnuform_ront_Click(objectsender,EventArgse){FontDialogfont=newFontDialog();font.ShowColor=true;font.Color=richTextBox1.SelectionColor;font.Font=richTextBox1.SelectionFont;if(font.ShowDialog()==DialogResult.OK){richTextBox1.SelectionFont=font.Font;richTextBox1.SelectionColor=font.Color;}}privatevoidmnuform_wordwrap_Click(objectsender,EventArgse){mnuform_wordwrap.Checked=richTextBox1.WordWrap;}privatevoidmnuform_color_Click(objectsender,EventArgse){ColorDialogcolor=newColorDialog();color.AllowFullOpen=true;color.AnyColor=true;color.Color=richTextBox1.SelectionColor;if(color.ShowDialog()==DialogResult.OK)richTextBox1.SelectionColor=color.Color;}privatevoidtimer1_Tick(objectsender,EventArgse){statu2.Text=DateTime.Now.ToLongTimeString();}privatevoidcopybutton_Click(objectsender,EventArgse){mnuedit_copy_Click(sender,e);}privatevoidcutbutton_Click(objectsender,EventArgse){mnuedit_cut_Click(sender,e);}privatevoidsavebutton_Click(objectsender,EventArgse){mnuedit_paste_Click(sender,e);}privatevoidnewbutton_Click(objectsender,EventArgse){mnuedit_new_Click(sender,e);}}}四、调试程序心得总结通过本次实验,我熟悉了容器、菜单与工具栏、对话框控件的使用,知道了它们的常用属性与方法,通过对话框进行windows应用程序的设计与实现,我学会综合运用菜单、工具栏、状态栏来生成一个简易记事本。在本次实验时,要想实验做的成功,要正确选取控件,设计好界面,并对属性进行设置,最后编写代码,实现结果。实验验中也我遇到了一些问题,比如一些控件找不到,在窗体上设置快捷菜单时,由于忘记了设置,运行过后,在记事本窗体上右击时不能出现快捷菜单,经过多次修改后,最终运行出了正确的结果。本次实验我收益很大,增加了我纠错改正的能力。
本文标题:CNET容器菜单与工具栏对话框控件的练习
链接地址:https://www.777doc.com/doc-2906458 .html