资源描述:
《界面设计和对话框课件.ppt》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、1本章教学目标菜单控件(MenuStrip)上下文菜单控件(ContextMenuStrip)工具栏控件(ToolStrip)状态栏控件(StatusStrip)打开文件对话框(OpenFileDialog)保存文件对话框(SaveFileDialog)字体对话框(FontDialog)颜色对话框(ColorDialog)8.1菜单8.1.1菜单选项与分隔条菜单项的设置分隔条(separator)8.1.2访问键和快捷键访问键(accesskey)Alt+key快捷键(shortcutkey)Ctrl+keyShift+key实例8.1例8.1创建一个菜单驱动,能实现
2、最简单文字编辑功能的记事本程序例8.1程序代码(1)usingSystem;usingSystem.Text;usingSystem.Windows.Forms;usingSystem.IO;//执行文件操作,必须引用这个命名空间namespaceex801{publicpartialclassForm1:Form{publicForm1(){InitializeComponent();}privatevoidmenuFileNew_Click(objectsender,EventArgse){File.Create(@"d:test1.rtf");Message
3、Box.Show("名为1.rtf的文件创建成功","创建文件");}}}例8.1程序代码(2)privatevoidmenuFileOpen_Click(objectsender,EventArgse)//打开文件{richTextBox1.LoadFile(@"d:test2.rtf",RichTextBoxStreamType.RichText);}privatevoidmenuFileSave_Click(objectsender,EventArgse)//保存文件{richTextBox1.SaveFile(@"d:test3.rtf");Messa
4、geBox.Show("名为3.rtf的文件保存成功","保存文件");}privatevoidmenuFileExit_Click(objectsender,EventArgse)//退出运行{this.Close();//结束程序,退出运行}例8.1程序代码(3)privatevoidmenuEditUndo_Click(objectsender,EventArgse)//撤消{if(richTextBox1.CanUndo==true)richTextBox1.Undo();//撤消在RichTextBox中所做的修改elseMessageBox.Show("无
5、法撤消");}privatevoidmenuEditCut_Click(objectsender,EventArgse)//剪切{richTextBox1.Cut();//将文本框中被选中的文字移动到剪贴板}privatevoidmenuEditCopy_Click(objectsender,EventArgse)//复制{richTextBox1.Copy();//将文本框中被选中的文字复制到剪贴板}privatevoidmenuEditPaste_Click(objectsender,EventArgse)//粘贴{richTextBox1.Paste();//将
6、剪贴板中的内容粘贴到文本框}例8.1程序代码(4)privatevoidmenuEditFind_Click(objectsender,EventArgse)//查找{//查找到第一个“迪斯尼”并将其选中intposition=richTextBox1.Text.IndexOf("迪斯尼");if(position>=0)richTextBox1.Select(position,3);}privatevoidmenuEditReplace_Click(objectsender,EventArgse)//替换{//将所有的“迪斯尼”替换为“Disney”stringst
7、r1=richTextBox1.SelectedText;richTextBox1.SelectedText=str1.Replace("迪斯尼","Disney");}例8.1程序代码(5)privatevoidmenuFormatFont_Click(objectsender,EventArgse)//字体{richTextBox1.SelectionFont=newFont("隶书",24,FontStyle.Bold);//设置字体}privatevoidmenuFormatColor_Click(objectsender,EventArgs