VB记事本的课程设计.doc_第1页
VB记事本的课程设计.doc_第2页
VB记事本的课程设计.doc_第3页
VB记事本的课程设计.doc_第4页
VB记事本的课程设计.doc_第5页
已阅读5页,还剩6页未读 继续免费阅读

下载本文档

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

文档简介

一 功能分析(1)目标:实现类似与WINDOWS平台下的记事本程序。(2)涉及功能:新建、打开、保存、另存为、退出、编辑、撤销、复制、粘贴、剪切、删除、查找、全选、打印、格式、字体、颜色、查看、状态栏、帮助、关于等二 设计安排(1)查资料(2)初步规划工程步骤(3)开始工程设计:1)建立一个标准的EXE工程。2)确定窗体Form1的主要属性:Caption 3)窗体中添加控件:Timer1 CommonDialog1 VScroll1 HScroll1 4)添加设置状态栏和工具栏5)编辑菜单控件属性6)编写代码 (4)运行工程 (5)结束三界面设计 见上传作业四控件属性设置控件名属性名属性值Timer1Interval1000CommonDialog1VScroll1HScroll1五状态栏属性设置索引Index样式说明1sbrtext显示当前时间2sbrdate显示当前日期3sbrins显示插入控制键的状态4sbrnum显示数字键盘的使用状态六菜单属性设置 见上传作业七代码设置Dim filecount As IntegerDim inputdata As StringDim TargetPosition As IntegerDim pos As IntegerDim targey As StringDim neirong As StringPrivate Sub Toolbar1_ButtonClick(ByVal Button As MSComCtlLib.Button)Select Case ButtonCase 新建Call mnunew_ClickCase 打开Call mnuopen_ClickCase 剪切Call mnuCut_ClickCase 复制Call mnucopy_ClickCase 粘贴Call mnupaste_ClickCase 保存Call mnusave_ClickCase 查找Call mnufind_ClickEnd SelectEnd SubPrivate Sub Toolbar2_ButtonClick(ByVal Button As MSComCtlLib.Button) On Error Resume Next Select Case Button.Key Case 新建 mnunew_Click Case 打开 mnuopen_Click Case 剪切 mnuCut_Click Case 粘贴 mnupaste_Click Case 保存 mnusave_Click Case 查找 mnufind_Click End Select End SubPrivate Sub Form_Load()StatusBar1.Panels(1).Text = Time Text1.Text = Text1.Left = 0 Text1.Top = 550 Text1.Width = Form1.ScaleWidth Text1.Height = Form1.ScaleHeight mnucut.Enabled = False mnucopy.Enabled = False mnudelete.Enabled = False mnuselectall.Enabled = False mnupaste.Enabled = True mnuleft.Checked = TrueEnd SubPrivate Sub Form_Resize() 如果窗体不处于最小化text1状态,改变text1大小以适应窗体大小变化 If Form1.WindowState 1 Then Text1.Width = Form1.Width - 120 If Form1.Height 1200 Then Form1.Height = 1200 End If Text1.Height = Form1.Height - 1350 End IfEnd SubPrivate Sub Form_Unload(Cancel As Integer)Dim msg As IntegerIf Text1.Text neirong Then msg = MsgBox( 内容已被修改,是否保存文件, 48 + vbYesNoCancel, 提示) If msg = vbYes Then On Error GoTo Err CommonDialog1.DialogTitle = 保存文件 CommonDialog1.Filter = 文本文件|*.txt CommonDialog1.CancelError = True CommonDialog1.ShowSave Open CommonDialog1.FileName For Output As #1 Print #1, Text1.Text Close #1Err: If Err.Number = cdlCancel Then Cancel = True End If ElseIf msg = vbNo Then End ElseIf msg = vbCancel Then Cancel = True End If Else End End IfEnd SubPrivate Sub mnunew_Click() 新建 Text1.Text = End SubPrivate Sub mnuopen_Click() 打开Dim inputdata As String On Error GoTo nofile CommonDialog1.Filter = 文本文件|*.txt CommonDialog1.CancelError = True CommonDialog1.ShowOpen Text1.Text = If CommonDialog1.FileName Then Open CommonDialog1.FileName For Input As #1 Do While Not EOF(1) Line Input #1, inputdata Text1.Text = Text1.Text & inputdata & vbCr Loop Close #1 End If Exit Subnofile: If Err.Number = 32755 Then Exit SubEnd SubPrivate Sub mnusave_Click() 保存 On Error Resume Next CommonDialog1.DialogTitle = 保存文件 CommonDialog1.Filter = 文本文件|*.txt CommonDialog1.CancelError = True CommonDialog1.ShowSave Open CommonDialog1.FileName For Output As #1 Print #1, Text1.Text Close #1End SubPrivate Sub mnusaveas_Click() 另存为On Error Resume NextCommonDialog1.Filter = 文本文件|*.txtCommonDialog1.CancelError = TrueCommonDialog1.Action = 2Open CommonDialog1.FileName For Output As #1Print #1, Text1.TextClose #1End SubPrivate Sub Text1_Change()If Text1.Text = Thenmnufind.Enabled = FalsemnuNext.Enabled = FalseElsemnufind.Enabled = Truemnuselectall.Enabled = TrueEnd IfEnd SubPrivate Sub mnuexit_Click() 退出 EndEnd SubPrivate Sub mnuedit_Click() 编辑 If Text1.SelLength 0 Then 如果文本框中没有选中的内容,则剪切复制删除和粘贴菜单无效,否则有效mnucut.Enabled = True mnucopy.Enabled = True mnudelete.Enabled = True mnupaste.Enabled = True Else mnucut.Enabled = False mnucopy.Enabled = False mnudelete.Enabled = False End IfEnd SubPrivate Sub mnucancel_Click() 撤销MsgBox 点击鼠标右键撤销!, vbOKOnly, 提示End SubPrivate Sub mnucopy_Click() 复制 利用SetText 方法,将选中的文本放入剪贴板上 Clipboard.SetText Text1.SelTextEnd SubPrivate Sub mnuCut_Click() 剪切 Clipboard.SetText Text1.SelText Text1.SelText = End SubPrivate Sub mnupaste_Click() 粘贴 用GetText1 方法,将剪切板中的内容粘贴到光标所在位置 Text1.SelText = Clipboard.GetText()End SubPrivate Sub mnuprint_Click() 打印On Error Resume Next CommonDialog1.ShowPrinter Printer.Copies = CommonDialog1.Copies Printer.Print Text1.TextEnd SubPrivate Sub mnudelete_Click() 删除Text1.SelText = End SubPrivate Sub mnuselectall_Click() 全选 Text1.SelStart = 0 Text1.SelLength = Len(Text1.Text)End SubPrivate Sub mnufont_Click() 字体On Error GoTo mnusave: CommonDialog1.Flags = cdlCFBoth Or cdlCFEffects CommonDialog1.ShowFont If CommonDialog1.FontName Then Text1.FontName = CommonDialog1.FontName End If Text1.FontSize = CommonDialog1.FontSize Text1.FontBold = CommonDialog1.FontBold Text1.FontItalic = CommonDialog1.FontItalic Text1.FontStrikethru = CommonDialog1.FontStrikethru Text1.FontUnderline = CommonDialog1.FontUnderline Text1.FontBold = CommonDialog1.FontBold Text1.ForeColor = CommonDialog1.Colormnusave: If Err.Number 0 Then 找到了匹配字符串 TargetPosition = posForm1.Text1.SelStart = TargetPosition - 1Form1.Text1.SelLength = Len(targey) 选中找到的字符串Form1.Text1.SetFocusElse 没有找到匹配的字符串MsgBox 没找到匹配的字符串, 48, 提示Form1.Text1.SetFocusEnd IfEnd SubPrivate Sub mnuright_Click(Index As Integer) 右对齐居中Select Case IndexCase 1Text1.Alignment = 1mnuleft.Checked = Falsemnuright(1).Checked = Truemnuright(2).Checked = FalseCase 2Text1.Alignment = 2mnuleft.Checked = Falsemnuright(1).Checked = Falsemnuright(2).Checked = TrueEnd SelectEnd SubPrivate Sub mnustatusbar_Click() 状态栏 If mnustatusbar.Checked Then StatusBar1.Visible = False mnustatusbar.Checked = False Else StatusBar1.Visible = True mnustatusbar.Checked = True End IfEnd SubPrivate Sub Timer1_Timer() 时钟If StatusBar1.Panels(1).Text CStr(Time) ThenStatusBar1.Panels(1).Text = TimeEnd IfEnd SubPrivate Sub mnuabout_Click() 关于MsgBox 记

温馨提示

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

评论

0/150

提交评论