用VB编写的记事本源码教程.docx

上传人:小飞机 文档编号:3658445 上传时间:2023-03-14 格式:DOCX 页数:10 大小:39.16KB
返回 下载 相关 举报
用VB编写的记事本源码教程.docx_第1页
第1页 / 共10页
用VB编写的记事本源码教程.docx_第2页
第2页 / 共10页
用VB编写的记事本源码教程.docx_第3页
第3页 / 共10页
用VB编写的记事本源码教程.docx_第4页
第4页 / 共10页
用VB编写的记事本源码教程.docx_第5页
第5页 / 共10页
亲,该文档总共10页,到这儿已超出免费预览范围,如果喜欢就下载吧!
资源描述

《用VB编写的记事本源码教程.docx》由会员分享,可在线阅读,更多相关《用VB编写的记事本源码教程.docx(10页珍藏版)》请在三一办公上搜索。

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

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

3、par4、查找find、查找下一个findnext、替换instead、转到zhuan、-spar5、全选selectall、时间/日期date (3)格式菜单 格式style、自动换行autozhuan、字体font (4)查看菜单 查看cha、状态栏state (5)帮助菜单 帮助help、帮助主题topic、关于记事本about 3.编辑代码 (1)新建 Private Sub new_Click Dim m As New Form1 If d Then If Form1.Caption = 无标题-记事本 Then yy = MsgBox(文件 无标题-记事本 文字已经改变, + Ch

4、r(13) + Chr(10) + 是否保存文件?, 51, 记事本) Else yy = MsgBox(文件 + rr + 文字已经改变, + Chr(13) + Chr(10) + 是否保存文件?, 51, 记事本) End If End If If yy = 6 Then Call lingsave_Click ElseIf yy = 2 Then Exit Sub End If Form1.Hide m.Show End Sub (2)打开 Private Sub open_Click cd.InitDir = D: cd.CancelError = True cd.Filter =

5、全部文挡(*.*)|*.*|文本文挡(*.txt)|*.txt cd.FilterIndex = 2 If 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) 2 Loop Text1.Text = whole$ Close #1 ss = Split(cd.FileTitle, .) dd =

6、ss(0) Form1.Caption = dd + -记事本 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 GoTo start Else Exit Sub End If End If ee: Exit Sub End Sub

7、 (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 End If End Sub (4)另存为 Private Sub lingsave_Click cd.InitDir = D: cd.CancelError = True On E

8、rror GoTo jj cd.Filter = 全部文挡(*.*)|*.*|文本文挡(*.txt)|*.txt cd.FilterIndex = 2 3 cd.ShowSave Open cd.FileName For Output As #2 Print #2, Text1.Text Close #2 d = False ss = Split(cd.FileTitle, .) dd = ss(0) Form1.Caption = dd + -记事本 jj: Exit Sub End Sub (5)打印 Private Sub print_Click Dim firpage, endpage

9、, num cd.CancelError = True On Error GoTo jj cd.ShowPrinter num = cd.Copies Printer.font = 楷体 Printer.FontSize = 10 Printer.PaperSize = vbPRPSA4 For i = 1 To num Printer.CurrentX = 10 Printer.CurrentY = 10 Printer.Print Text1.Text Next i Printer.EndDoc Exit Sub jj: Exit Sub End Sub (6)退出 Private Sub

10、 exit_Click End End Sub (7)剪切 Private Sub qie_Click Clipboard.Clear Clipboard.SetText Text1.SelText Text1.SelText = End Sub (8)复制 Private Sub copy_Click Clipboard.Clear Clipboard.SetText Text1.SelText 4 End Sub (9)粘贴 Private Sub tie_Click Text1.SelText = Clipboard.GetText End Sub 查找 Private Sub find

11、_Click Form2.Show End Sub Form2中代码: 注:dd、ee都是全局变量 Private Sub Command1_Click If Check1.Value = 1 Then dd = InStr(Form1.Text1.Text, Form2.Text1.Text) Else dd = InStr(LCase(Form1.Text1.Text), LCase(Form2.Text1.Text) End If ee = Len(Form2.Text1.Text) Form1.Text1.SelStart = dd - 1 Form1.Text1.SelLength

12、= ee kk = kk + 1 Form1.SetFocus End Sub Private Sub Command2_Click Form2.Hide End Sub 替换 Private Sub instead_Click Form3.Show End Sub Form3中的内容 Private Sub Command1_Click If Check1.Value = 1 Then If dd none And ee none Then ff = InStr(dd + ee, LCase(Form1.Text1.Text), LCase(Form3.Text1.Text) Else ff

13、 = 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 + 1 Else 5 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

14、.Text), LCase(Form3.Text1.Text) End If Form1.Text1.SelStart = ff - 1 dd = ff ee = Len(Text1.Text) Form1.Text1.SelLength = ee kk = kk + 1 End If Form1.SetFocus End Sub Private Sub Command2_Click Form1.Text1.SelText = Text2.Text End Sub Private Sub Command3_Click Do While (dd + ee) Len(Form1.Text1.Tex

15、t) 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(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

16、dd 0 And ee 0 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 Form1.SetFocus End If Form1.Text1.SelText = Text2.Text

17、 Loop End Sub 6 Private Sub Command4_Click Form3.Hide End Sub (10)全选 Private Sub selectall_Click Text1.SelStart = Len(RTrim(Text1.Text) - Len(Trim(Text1.Text) Text1.SelLength = Len(Text1.Text) End Sub (11)时间/日期 Private Sub date_Click Text1.SelText = Now End Sub (12)字体 Private Sub font_Click cd.Flags

18、 = 259 cd.ShowFont Text1.FontBold = cd.FontBold Text1.FontItalic = cd.FontItalic Text1.FontName = cd.FontName Text1.FontUnderline = cd.FontUnderline Text1.FontStrikethru = cd.FontStrikethru Text1.ForeColor = cd.Color End Sub 其它事件 Private Sub Form_Resize Text1.Width = ScaleWidth Text1.Height = ScaleH

19、eight End Sub Private Sub Text1_Change d = True End Sub Private 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 selectall.Enabled = True End If zhuan.Enabled = False Else qie.Enabled

20、 = False 7 copy.Enabled = False delete.Enabled = False instead.Enabled = True date.Enabled = True selectall.Enabled = True zhuan.Enabled = False If Len(Text1.Text) 0 Then find.Enabled = True findnext.Enabled = True Else find.Enabled = False findnext.Enabled = False End If End If If Clipboard.GetText Then tie.Enabled = True Else tie.Enabled = False End If If d = True Then cancel.Enabled = True Else cancel.Enabled = False End If End Sub 变量 Form1通用中Dim d As Boolean Dim rr Module1中定义的全局变量:Public dd As Integer, ee As Integer Public kk As Integer 五、总结 通过编写记事本,我进一步熟悉了所学VB的程序语言,成功的编写了一个记事本。 8

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 生活休闲 > 在线阅读


备案号:宁ICP备20000045号-2

经营许可证:宁B2-20210002

宁公网安备 64010402000987号