《VB程序设计说明.docx》由会员分享,可在线阅读,更多相关《VB程序设计说明.docx(11页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、VB程序设计说明 选题介绍及意义,程序模块及功能,程序流程图,程序源码及注释,程序的后续完善及存在问题,设计程序的心得体会 一选题说明及意义 用VB实现备忘录的基本功能,包括记事本,屏幕抓图,数字时钟和日历等功能,利用VB中的诸多控件,例如 PictureBox,Label,CommendButton,Timer,CommendDialog,RichTextBox等,完成VB程序的诸多功能的实现,创建功能较为完善的记事本,并具有一定辅助功能,对于利用此软件的人能够具有一定的便利。 二程序模块及功能实现流程图 三部分程序代码 1.屏幕截图部分 Private Declare Function G
2、etDC Lib user32 (ByVal hwnd As Long) As Long Private Declare Function StretchBlt Lib gdi32 (ByVal hdc As Long, ByVal X As Long, ByVal Y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal nSrcWidth As Long, ByVal nSrcHeight As Lon
3、g, ByVal dwRop As Long) As Long Private Sub Command1_Click() Dim wScreen As Long Dim hScreen As Long Dim w As Long Dim h As Long Picture1.Cls wScreen = Screen.Width Screen.TwipsPerPixelX hScreen = Screen.Height Screen.TwipsPerPixelY 定义截屏的长度和宽度等于屏幕实际长宽 Picture1.ScaleMode = vbPixels w = Picture1.Scale
4、Width h = Picture1.ScaleHeight hdcScreen = GetDC(0) r = StretchBlt(Picture1.hdc, 0, 0, w, h, hdcScreen, 0, 0, wScreen, hScreen, vbSrcCopy) StretchBlt,函数名。该函数从源矩形中复制一个位图到目标矩形,必要时按目标设备设置的模式进行图像的拉伸或压缩。 End Sub Private Sub Command2_Click() 另存为按键代码 Me.Picture = Me.Image CommonDialog1.Filter = BMP文件(*.bmp
5、)|*.bmp|JPG文件 (*.jpg)|*.jpg CommonDialog1.ShowSave CommonDialog1.Flags = &H2 + &H4 + &H8 &H2使用长文件名 &H4 隐藏只读复选框。 &H8强制对话框将对话框打开时的目录置成当前目录 If CommonDialog1.FileName Then SavePicture Me.Picture, CommonDialog1.FileName End If End Sub Private Sub Command3_Click() 退出按键代码 Form3.Hide form6.Show End Sub 2.登陆
6、部分 Option Explicit Dim Npass As Integer Private Sub Command1_Click() If username.Text = 111 And password.Text = 111 And Npass 3 Then Form5.Hide Form2.Show Else Npass = Npass + 1 If Npass = 3 Then MsgBox 你没有机会了 End Else MsgBox 密码第 & Npass & 错误! 请再试一次., 0, 密码输入错误 password.Text = password.SetFocus End
7、If End If End Sub Private Sub Command2_Click() username.Text = password.Text = End Sub 3.日记本部分代码 Dim sfind As String Dim FileType, FiType As String Private Sub copy_Click() 复制按键 Clipboard.Clear On Error Resume Next Clipboard.SetText TxtDemo.SelText End Sub Private Sub date_Click() 日期按键 Text1.SelText
8、 = Now End Sub Private Sub delete_Click() 删除按键 RichTextBox1.SelText = End Sub Private Sub edits_Click() 编辑按键 RichTextBox1.SetFocus End Sub Private Sub exit_Click() 退出按键 Form2.Hide Form1.Show End Sub Private Sub find_Click() 查找按键 Dim sfind As Integer sfind = InputBox(请输入要查找的词:, 查找内容, sfind) RichTextB
9、ox1.find sfind If RichTextBox1.SelText sfind Then MsgBox 找不到要查询的内容, , 查询结果报告 End If End Sub Private Sub Form_Load() Me.Height = 6000 Me.Width = 9000 On Error Resume Next 出错处理 RichTextBox1.Top = 20 RichTextBox1.Left = 20 RichTextBox1.Height = ScaleHeight - 40 RichTextBox1.Width = ScaleWidth - 40 End
10、Sub Private Sub new_Click(Index As Integer) 新建按键RichTextBox1.Text = 清空文本框 FileName = 未命名 Me.Caption = FileName End Sub Private Sub open_Click() 打开部分CommonDialog1.Filter = 文本文档(*.txt)|*.txt|RTF文档(*.rtf)|*.rtf|所有文件(*.*)|*.* CommonDialog1.ShowOpen RichTextBox1.Text = 清空文本框 FileName = CommonDialog1.File
11、Name RichTextBox1.LoadFile FileName Me.Caption = 记事本: & FileName End Sub Private Sub paste_Click() Clipboard.Clear On Error Resume Next Clipboard.SetText RichTextBox1.SelText RichTextBox1.SelText = End Sub Private Sub riji_Click() 帮助日记部分MsgBox 日记Ver1.0版权所有(C)网络, vbOKOnly, 关于 End Sub Private Sub save
12、_Click() 保存文件部分 CommonDialog1.Filter = 文本文档(*.txt)|*.txt|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 RichTex
13、tBox1.SaveFile FileName, rtfRTF Case *.* RichTextBox1.SaveFile FileName End Select Me.Caption = 记事本: & FileName End Sub Private Sub selectall_Click() 全选部分RichTextBox1.SelStart = 0 RichTextBox1.SelLength = Len(RichTextBox1.Text) End Sub Private Sub tie_Click() 剪切部分 On Error Resume Next RichTextBox1.S
14、elText = Clipboard.GetText RichTextBox1.SelText = End Sub 4.数字时钟部分代码 Private LastMinute As Integer Private LastHour As Integer Private Lastx As Integer Private Lasty As Integer Private Sub Form_Load() Lastx = 999 End Sub Private Sub Timer1_Timer() Const pi = 3.141592653 定义圆周率Dim T Dim X As Integer D
15、im Y As Integer T = Now SEC = Second(T) Min = Minute(T) HR = Hour(T) frmClock.Scale (-16, 16)-(16, -16) If Min lastMin Or HR LastHour Then LastMinute = Min LastHour = HR frmClock.Cls Lastx = 999 frmClock.DrawWidth = 2 frmClock.DrawMode = 13 h = HR + pi / 60 X = 5 * Sin(h * pi / 6) Y = 5 * Cos(h * pi
16、 / 6) frmClock.Line (0, 0)-(X, Y) X = 8 * Sin(Min * pi / 30) Y = 8 * Cos(Min * pi / 30) frmClock.Line (0, 0)-(X, Y) frmClock.DrawWidth = 1 End If frmClock.DrawMode = 10 RED = RGB(255, 0, 0) X = 10 * Sin(SEC * pi / 30) Y = 10 * Cos(SEC * pi / 30) If Lastx 999 Then frmClock.Line (0, 0)-(Lastx, Lasty),
17、 RED End If frmClock.Line (0, 0)-(X, Y), RED Lastx = X Lasty = Y End Sub Private Sub NoUse_Click() Unload Me End Sub 四程序后续完善及存在问题 目前程序功能较为简单,对于备忘录部分只能实现简单的文字输入和截屏,日历,数字时钟的功能,在以后陆续的开发中会实现更多更复杂的功能,例如定时提醒,连接数据库,Excel表格等功能,程序在设计之初与最后成品稍有 不同,对于程序设计中部分功能未能实现,十分遗憾,在以后的学习中会加强程序设计部分知识,逐渐完善程序功能。 五设计程序的心得体会 通过此次程序设计,我对于VB程序语言和VB各类控件有了更深入的了解,对于综合VB各项函数等也有了更深入的学习,完成一个综合的作品对于学习编程语言来说是进阶必不可少的一部分,通过完成自己的作品也激发了我的创造思维和创作能力。在以后的学习中,我也会继续学习和深入了解编程语言,为更好的做学术研究打基础。
限制150内