您好,欢迎访问三七文档
当前位置:首页 > 商业/管理/HR > 管理学资料 > 用VB编写的记事本源码教程
一.实验要求用所学的VB语言编写一个自己的记事本,其功能与计算机中记事本的功能基本一致,程序结构清晰。二.实验目的通过编写记事本,熟悉并掌握所学VB的程序语言,锻炼编程思想,从而触类旁通发挥自己的创造力编辑自己的作品。三.设计软件所实现的功能窗体界面包括:文件、编辑、格式、查看、帮助五个主菜单。每个主菜单都有自己的子菜单,其主菜单的功能如下:1.文件:包括新建、打开、保存、另存为、页面设置、打印、退出的功能。2.编辑:包括撤销、剪切、复制、粘贴、删除、查找、查找下一个、替换、转到、全选、时间/日期的功能。3.格式:包括自动换行、字体的功能。4.查看:包括状态栏的功能5.帮助:包括帮助主题,关于记事本。四.设计介绍.1.绘制界面新建一个标准的.exe工程,将其caption属性改为”无标题-记事本”,点击icon属性给它找一个合适的图标,其编辑的界面图如下:2.编辑菜单按ctrl+E调出菜单编辑器,来做如下几个菜单:(1)文件菜单:文件(第一层)file、新建(第二层)new、打开(第二层)open、保存(第二层)save、另存为(第二层)lingsave、-(第二层)spar1(分隔线)、页面设置(第二层)design、打印(第二层)print、-(第二层)spar2(分隔线)、退出(第二层)exit(2)编辑菜单编辑(第一层)edit、撤销(第二层)cancel、-(第二层)spar3、剪切(第二层)qie、复制(第二层)copy、粘贴(第二层)tie、删除(第二层)delete、-(第二层)spar4、2查找(第二层)find、查找下一个(第二层)findnext、替换(第二层)instead、转到(第二层)zhuan、-(第二层)spar5、全选(第二层)selectall、时间/日期(第二层)date(3)格式菜单格式(第一层)style、自动换行(第二层)autozhuan、字体(第二层)font(4)查看菜单查看(第一层)cha、状态栏(第二层)state(5)帮助菜单帮助(第一层)help、帮助主题(第二层)topic、关于记事本(第二层)about3.编辑代码(1)新建PrivateSubnew_Click()DimmAsNewForm1IfdThenIfForm1.Caption=无标题-记事本Thenyy=MsgBox(文件无标题-记事本文字已经改变,+Chr(13)+Chr(10)+是否保存文件?,51,记事本)Elseyy=MsgBox(文件+rr+文字已经改变,+Chr(13)+Chr(10)+是否保存文件?,51,记事本)EndIfEndIfIfyy=6ThenCalllingsave_ClickElseIfyy=2ThenExitSubEndIfForm1.Hidem.ShowEndSub(2)打开PrivateSubopen_Click()cd.InitDir=D:cd.CancelError=Truecd.Filter=全部文挡(*.*)|*.*|文本文挡(*.txt)|*.txtcd.FilterIndex=2IfdTrueThenstart:OnErrorGoToeecd.ShowOpenOpencd.FileNameForInputAs#1rr=cd.FileNameDoWhileNotEOF(1)LineInput#1,a$whole$=whole$+a$+Chr(13)+Chr(10)3LoopText1.Text=whole$Close#1ss=Split(cd.FileTitle,.)dd=ss(0)Form1.Caption=dd+-记事本ElseIfForm1.Caption=无标题-记事本Thenyy=MsgBox(文件无标题-记事本文字已经改变,是否保存文件?,51,记事本)Elseyy=MsgBox(文件+rr+文字已经改变,是否保存文件?,51,记事本)EndIfIfyy=6ThenCalllingsave_ClickGoTostartElseIfyy=7ThenGoTostartElseExitSubEndIfEndIfee:ExitSubEndSub(3)保存PrivateSubsave_Click()IfForm1.Caption=无标题-记事本ThenCalllingsave_Clickd=FalseElsecc=Split(Form1.Caption,-)ff=cc(0)Openff+.txtForOutputAs#1Print#1,Text1.TextClose#1d=FalseEndIfEndSub(4)另存为PrivateSublingsave_Click()cd.InitDir=D:cd.CancelError=TrueOnErrorGoTojjcd.Filter=全部文挡(*.*)|*.*|文本文挡(*.txt)|*.txtcd.FilterIndex=24cd.ShowSaveOpencd.FileNameForOutputAs#2Print#2,Text1.TextClose#2d=Falsess=Split(cd.FileTitle,.)dd=ss(0)Form1.Caption=dd+-记事本jj:ExitSubEndSub(5)打印PrivateSubprint_Click()Dimfirpage,endpage,numcd.CancelError=TrueOnErrorGoTojjcd.ShowPrinternum=cd.CopiesPrinter.font=楷体Printer.FontSize=10Printer.PaperSize=vbPRPSA4Fori=1TonumPrinter.CurrentX=10Printer.CurrentY=10Printer.PrintText1.TextNextiPrinter.EndDocExitSubjj:ExitSubEndSub(6)退出PrivateSubexit_Click()EndEndSub(7)剪切PrivateSubqie_Click()Clipboard.ClearClipboard.SetTextText1.SelTextText1.SelText=EndSub(8)复制PrivateSubcopy_Click()Clipboard.ClearClipboard.SetTextText1.SelText5EndSub(9)粘贴PrivateSubtie_Click()Text1.SelText=Clipboard.GetTextEndSub(10)查找PrivateSubfind_Click()Form2.ShowEndSubForm2中代码:注:dd、ee都是全局变量PrivateSubCommand1_Click()IfCheck1.Value=1Thendd=InStr(Form1.Text1.Text,Form2.Text1.Text)Elsedd=InStr(LCase(Form1.Text1.Text),LCase(Form2.Text1.Text))EndIfee=Len(Form2.Text1.Text)Form1.Text1.SelStart=dd-1Form1.Text1.SelLength=eekk=kk+1Form1.SetFocusEndSubPrivateSubCommand2_Click()Form2.HideEndSub(11)替换PrivateSubinstead_Click()Form3.ShowEndSubForm3中的内容PrivateSubCommand1_Click()IfCheck1.Value=1ThenIfddnoneAndeenoneThenff=InStr(dd+ee,LCase(Form1.Text1.Text),LCase(Form3.Text1.Text))Elseff=InStr(LCase(Form1.Text1.Text),LCase(Form3.Text1.Text))EndIfForm1.Text1.SelStart=ff-1dd=ffee=Len(Text1.Text)Form1.Text1.SelLength=eekk=kk+1Else6IfddnoneAndeenoneThenff=InStr(dd+ee,LCase(Form1.Text1.Text),LCase(Form3.Text1.Text))Elseff=InStr(LCase(Form1.Text1.Text),LCase(Form3.Text1.Text))EndIfForm1.Text1.SelStart=ff-1dd=ffee=Len(Text1.Text)Form1.Text1.SelLength=eekk=kk+1EndIfForm1.SetFocusEndSubPrivateSubCommand2_Click()Form1.Text1.SelText=Text2.TextEndSubPrivateSubCommand3_Click()DoWhile(dd+ee)Len(Form1.Text1.Text)IfCheck1.Value=1ThenIfdd0Andee0Thenff=InStr(dd+ee,LCase(Form1.Text1.Text),LCase(Form3.Text1.Text))Elseff=InStr(LCase(Form1.Text1.Text),LCase(Form3.Text1.Text))EndIfForm1.Text1.SelStart=ff-1dd=ffee=Len(Text1.Text)Form1.Text1.SelLength=eeForm1.SetFocusElseIfdd0Andee0Thenff=InStr(dd+ee,LCase(Form1.Text1.Text),LCase(Form3.Text1.Text))Elseff=InStr(LCase(Form1.Text1.Text),LCase(Form3.Text1.Text))EndIfForm1.Text1.SelStart=ff-1dd=ffee=Len(Text1.Text)Form1.Text1.SelLength=eeForm1.SetFocusEndIfForm1.Text1.SelText=Text2.TextLoopEndSub7PrivateSubCommand4_Click()Form3.HideEndSub(10)全选PrivateSubselectall_Click()Text1.SelStart=Len(RTrim(Text1.Text))-Len(Trim(Text1.Text))Text1.SelLength=Len(Text1.Text)EndSub(11)时间/日期PrivateSubdate_Click()Text1.SelText=NowEndSub(12)字体PrivateSubfont_Click()cd.Flags=259cd.ShowFontText1.FontBold=cd.FontBoldText1.FontItalic=cd.FontItalicText1.FontName=cd.FontNameText1.FontUnderline=cd.FontUnderlineText1.FontStrikethru=cd.FontStrikethruText1.ForeColor=cd.ColorEndSub(13)其它事件PrivateSubForm_Resize()Text1.Width=ScaleWidthText1.Height=ScaleHeightEndSubPrivateSubText1_Change()d=TrueEndSubPrivateSubTimer1_Timer()IfText1.SelTextThenq
本文标题:用VB编写的记事本源码教程
链接地址:https://www.777doc.com/doc-5926911 .html