范文无忧网学习方法学习技巧

用VB2005如何编一个记事本

01月07日 编辑 fanwen51.com

[关于国庆节记事1000字]关于国庆节记事1000字1: 盼星星,盼月亮,终于把十一长假盼来了,心中情不自禁地欢喜起来,幻想着与爸爸妈妈一起远足的快乐时光即将到来,我更是乐得合不拢嘴。 还未解放呢,我就激动得...+阅读

最近在学习VB,一直想编写自己的一个作品看看自己的学习成果,最早的时候刚刚开始学,想起了写个记事本给自己用.后来开始着手,经过最近的修改和老师的指导,做出了现在的程序,还有部分功能未添加,以后会慢慢完善,在学校上机的时间都没有,更别说上网了...会等很长时间的. 开始说这个记事本,这次做的不好,比较简陋,第一次做,望大家指导!采用了2个控件,richtextbox控件和CommonDialog控件.下面是完整的代码Dim sFind As String '注释: 声明查找变量 Dim FileType, FiType As String '注释: 声明文件类型 Private Sub Form_Load() '注释: 设置程序启动时的大小 Me.Height = 6000 Me.Width = 9000 End SubPrivate Sub Form_Resize() On Error Resume Next '注释:出错处理 RichTextBox1.SelColor = vbGreen '默认字体颜色 Me.RichTextBox1.BackColor = vbBlack RichTextBox1.Top = 20 RichTextBox1.Left = 20 RichTextBox1.Height = ScaleHeight - 40 RichTextBox1.Width = ScaleWidth - 40 End SubPrivate Sub RichTextBox1_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single) If KeyCode = vbKeySpace Then RichTextBox1.SelFontName = CommonDialog1.FontName End If End SubPrivate Sub RichTextBox1_Change() If RichTextBox1.Text = "" Then xinjian.Enabled = False baocun.Enabled = False chazhao.Enabled = False chazhao1.Enabled = False Else xinjian.Enabled = True baocun.Enabled = True chazhao.Enabled = True chazhao1.Enabled = True End If End SubPrivate Sub shiyong_Click() On Error GoTo handler RichTextBox1.LoadFile "Readme.txt", rtfText '注释:请写好Readme.txt文件并存入程序所在文件夹中 Me.Caption = "专用记事本:" & "使用说明" Exit Sub handler:MsgBox "使用说明文档可能已经被移除,请与作者联系。

", vbOKOnly, " 错误信息" End SubPrivate Sub guanyu_Click() MsgBox "专用记事本 Ver1.0 版权所有(C) 2007 ", vbOKOnly, "关于" End Sub Private Sub open_Click() Dim strtxt As String CommonDialog1.FileName = "" CommonDialog1.Flags = vbofnfilemustexist CommonDialog1.Filter = "全部文件(*.*)|*.*|word(文档)(*.doc)|*.doc|文本文件(*.txt)|*.txt" CommonDialog1.FilterIndex = 1 RichTextBox1.SelColor = vbGreen RichTextBox1.Text = "" CommonDialog1.DialogTitle = "专用记事本-打开" CommonDialog1.Action = 1 If CommonDialog1.FileName = "" Then Close Else Open CommonDialog1.FileName For Input As #1 If Err.Number = 0 Then Do While Not EOF(1) Input #1, strtxt$ RichTextBox1.Text = RichTextBox1.Text + strtxt$ + vbCrLf Loop Close #1 End If End If Me.RichTextBox1.SelStart = 0 Me.RichTextBox1.SelLength = Len(RichTextBox1.Text) Me.RichTextBox1.SelColor = vbGreen Me.RichTextBox1.BackColor = vbBlack Me.RichTextBox1.Refresh End SubPrivate Sub xinjian_Click() RichTextBox1.Text = "" '注释:清空文本框 FileName = "未命名" Me.Caption = FileName Me.RichTextBox1.SelColor = vbGreen Me.RichTextBox1.BackColor = vbBlack End Sub Private Sub baocun_Click() CommonDialog1.Filter = "文本文档(*.txt)|*.txt|word文档(*.doc)|(*.doc)|RTF文档(*.rtf)|*.rtf|所有文件(*.*)|*.*" CommonDialog1.ShowSave FileType = CommonDialog1.FileTitle FiType = LCase(Right(FileType, 3)) FileName = CommonDialog1.FileName Select Case FiType Case "txt" RichTextBox1.SaveFile FileName, rtfText Case "rtf" RichTextBox1.SaveFile FileName, rtfRTF Case "*.*" RichTextBox1.SaveFile FileName End Select Me.Caption = "专用记事本:" & FileName End Sub Private Sub tuichu_Click() End End SubPrivate Sub yanse_Click() CommonDialog1.Action = 3 '显示字体颜色拾取框 Me.RichTextBox1.SelColor = CommonDialog1.Color End SubPrivate Sub chazhao_Click() sFind = InputBox("请输入要查找的字,词:", "查找内容", sFind) '查找代码 RichTextBox1.Find sFind End SubPrivate Sub chazhao1_Click() RichTextBox1.SelStart = RichTextBox1.SelStart + RichTextBox1.SelLength + 1 '继续查找下一个内容 RichTextBox1.Find sFind, , Len(RichTextBox1) End Sub注:在此补上图片,模仿微软的记事本.

推荐阅读
图文推荐
栏目列表