用VB编写的记事本源码教程_第1页
用VB编写的记事本源码教程_第2页
用VB编写的记事本源码教程_第3页
用VB编写的记事本源码教程_第4页
用VB编写的记事本源码教程_第5页
已阅读5页,还剩3页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、精选优质文档-倾情为你奉上一实验要求用所学的VB语言编写一个自己的记事本,其功能与计算机中记事本的功能基本一致,程序结构清晰。二实验目的通过编写记事本,熟悉并掌握所学VB的程序语言,锻炼编程思想,从而触类旁通发挥自己的创造力编辑自己的作品。三设计软件所实现的功能窗体界面包括:文件、编辑、格式、查看、帮助五个主菜单。每个主菜单都有自己的子菜单,其主菜单的功能如下:1. 文件:包括新建、打开、保存、另存为、页面设置、打印、退出的功能。2. 编辑:包括撤销、剪切、复制、粘贴、删除、查找、查找下一个、替换、转到、全选、时间/日期的功能。3. 格式:包括自动换行、字体的功能。4. 查看:包括状态栏的功能

2、5. 帮助:包括帮助主题,关于记事本。四设计介绍.1.绘制界面新建一个标准的.exe工程,将其caption属性改为”无标题-记事本”,点击icon属性给它找一个合适的图标,其编辑的界面图如下:2.编辑菜单按ctrl+E调出菜单编辑器,来做如下几个菜单:(1)文件菜单:文件(第一层)file、新建(第二层)new、打开(第二层)open、保存(第二层)save、另存为(第二层)lingsave、-(第二层)spar1(分隔线)、 页面设置(第二层)design、打印(第二层)print、-(第二层)spar2(分隔线)、退出(第二层)exit(2)编辑菜单编辑(第一层)edit、撤销(第二层)

3、cancel、-(第二层)spar3、剪切(第二层)qie、复制(第二层)copy、粘贴(第二层)tie、删除(第二层)delete、-(第二层)spar4、查找(第二层)find、查找下一个(第二层)findnext、替换(第二层)instead、转到(第二层)zhuan、-(第二层)spar5、全选(第二层)selectall、时间/日期(第二层)date(3)格式菜单格式(第一层)style、自动换行(第二层)autozhuan、字体(第二层)font(4)查看菜单查看(第一层)cha、状态栏(第二层)state(5)帮助菜单帮助(第一层)help、帮助主题(第二层)topic、关于记事

4、本(第二层)about3.编辑代码(1)新建Private Sub new_Click()Dim m As New Form1If d Then If Form1.Caption = "无标题-记事本" Then yy = MsgBox("文件 无标题-记事本 文字已经改变," + Chr(13) + Chr(10) + "是否保存文件?", 51, "记事本") Else yy = MsgBox("文件 " + rr + " 文字已经改变," + Chr(13) + Chr

5、(10) + "是否保存文件?", 51, "记事本") End IfEnd IfIf yy = 6 Then Call lingsave_ClickElseIf yy = 2 Then Exit Sub End IfForm1.Hidem.ShowEnd Sub(2)打开Private Sub open_Click()cd.InitDir = "D:"cd.CancelError = Truecd.Filter = "全部文挡(*.*)|*.*|文本文挡(*.txt)|*.txt"cd.FilterIndex =

6、 2If d <> True Then start: On Error GoTo ee cd.ShowOpen Open cd.FileName For Input As #1 rr = cd.FileName Do While Not EOF(1) Line Input #1, a$ whole$ = whole$ + a$ + Chr(13) + Chr(10) Loop Text1.Text = whole$ Close #1 ss = Split(cd.FileTitle, ".") dd = ss(0) Form1.Caption = dd + &qu

7、ot;-记事本" Else If Form1.Caption = "无标题-记事本" Then yy = MsgBox("文件 无标题-记事本 文字已经改变,是否保存文件?", 51, "记事本") Else yy = MsgBox("文件 " + rr + " 文字已经改变,是否保存文件?", 51, "记事本") End If If yy = 6 Then Call lingsave_Click GoTo start ElseIf yy = 7 Then GoT

8、o start Else Exit Sub End IfEnd Ifee: Exit SubEnd Sub(3)保存Private Sub save_Click() If Form1.Caption = "无标题-记事本" Then Call lingsave_Click d = False Else cc = Split(Form1.Caption, "-") ff = cc(0) Open ff + ".txt" For Output As #1 Print #1, Text1.Text Close #1 d = False En

9、d IfEnd Sub(4)另存为Private Sub lingsave_Click()cd.InitDir = "D:"cd.CancelError = TrueOn Error GoTo jjcd.Filter = "全部文挡(*.*)|*.*|文本文挡(*.txt)|*.txt"cd.FilterIndex = 2cd.ShowSaveOpen cd.FileName For Output As #2Print #2, Text1.TextClose #2d = False ss = Split(cd.FileTitle, ".&quo

10、t;) dd = ss(0) Form1.Caption = dd + "-记事本"jj: Exit SubEnd Sub(5)打印Private Sub print_Click()Dim firpage, endpage, numcd.CancelError = TrueOn Error GoTo jjcd.ShowPrinternum = cd.CopiesPrinter.font = "楷体"Printer.FontSize = 10Printer.PaperSize = vbPRPSA4For i = 1 To num Printer.Curre

11、ntX = 10 Printer.CurrentY = 10 Printer.Print Text1.TextNext iPrinter.EndDocExit Subjj:Exit SubEnd Sub(6)退出Private Sub exit_Click()EndEnd Sub(7)剪切Private Sub qie_Click() Clipboard.Clear Clipboard.SetText Text1.SelText Text1.SelText = ""End Sub(8)复制Private Sub copy_Click()Clipboard.ClearClip

12、board.SetText Text1.SelText End Sub(9)粘贴Private Sub tie_Click()Text1.SelText = Clipboard.GetTextEnd Sub(10)查找Private Sub find_Click()Form2.ShowEnd SubForm2中代码:注:dd、ee都是全局变量Private Sub Command1_Click()If Check1.Value = 1 Thendd = InStr(Form1.Text1.Text, Form2.Text1.Text)Elsedd = InStr(LCase(Form1.Tex

13、t1.Text), LCase(Form2.Text1.Text)End Ifee = Len(Form2.Text1.Text)Form1.Text1.SelStart = dd - 1Form1.Text1.SelLength = eekk = kk + 1Form1.SetFocusEnd SubPrivate Sub Command2_Click()Form2.HideEnd Sub(11)替换Private Sub instead_Click()Form3.ShowEnd SubForm3中的内容Private Sub Command1_Click()If Check1.Value

14、= 1 Then If dd <> none And ee <> none Then ff = InStr(dd + ee, LCase(Form1.Text1.Text), LCase(Form3.Text1.Text) Else ff = InStr(LCase(Form1.Text1.Text), LCase(Form3.Text1.Text) End If Form1.Text1.SelStart = ff - 1 dd = ff ee = Len(Text1.Text) Form1.Text1.SelLength = ee kk = kk + 1Else If

15、 dd <> none And ee <> none Then ff = InStr(dd + ee, LCase(Form1.Text1.Text), LCase(Form3.Text1.Text) Else ff = InStr(LCase(Form1.Text1.Text), LCase(Form3.Text1.Text) End If Form1.Text1.SelStart = ff - 1 dd = ff ee = Len(Text1.Text) Form1.Text1.SelLength = ee kk = kk + 1End IfForm1.SetFoc

16、usEnd SubPrivate Sub Command2_Click()Form1.Text1.SelText = Text2.TextEnd SubPrivate Sub Command3_Click()Do While (dd + ee) < Len(Form1.Text1.Text) If Check1.Value = 1 Then If dd <> 0 And ee <> 0 Then ff = InStr(dd + ee, LCase(Form1.Text1.Text), LCase(Form3.Text1.Text) Else ff = InStr(

17、LCase(Form1.Text1.Text), LCase(Form3.Text1.Text) End If Form1.Text1.SelStart = ff - 1 dd = ff ee = Len(Text1.Text) Form1.Text1.SelLength = ee Form1.SetFocus Else If dd <> 0 And ee <> 0 Then ff = InStr(dd + ee, LCase(Form1.Text1.Text), LCase(Form3.Text1.Text) Else ff = InStr(LCase(Form1.T

18、ext1.Text), LCase(Form3.Text1.Text) End If Form1.Text1.SelStart = ff - 1 dd = ff ee = Len(Text1.Text) Form1.Text1.SelLength = ee Form1.SetFocus End If Form1.Text1.SelText = Text2.TextLoopEnd SubPrivate Sub Command4_Click()Form3.HideEnd Sub(10)全选Private Sub selectall_Click()Text1.SelStart = Len(RTrim

19、(Text1.Text) - Len(Trim(Text1.Text)Text1.SelLength = Len(Text1.Text)End Sub(11)时间/日期Private Sub date_Click()Text1.SelText = NowEnd Sub(12)字体Private Sub font_Click()cd.Flags = 259cd.ShowFontText1.FontBold = cd.FontBoldText1.FontItalic = cd.FontItalicText1.FontName = cd.FontNameText1.FontUnderline = c

20、d.FontUnderlineText1.FontStrikethru = cd.FontStrikethruText1.ForeColor = cd.ColorEnd Sub(13)其它事件Private Sub Form_Resize()Text1.Width = ScaleWidthText1.Height = ScaleHeightEnd SubPrivate Sub Text1_Change()d = TrueEnd SubPrivate Sub Timer1_Timer()If Text1.SelText <> "" Then qie.Enabled = True copy.Enabled = True delete.Enabled = True If Text1.SelText = Text1.Text Then selectall.Enabled = False Else selectal

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论