【 tulaoshi.com - vb 】
1) 首先新建一EXE工程
在工程菜单-部件菜单中选择MICROSOFT COMMON DIALOG CONTROL 6.0(SP3)和MICROSOFT WINDOWS COMMON CONTROLS 6.0(SP4)两项,在工程菜单-引用菜单中选择MICROSOFT SCRIPTING RUNTIME项,然后保存工程,再在窗体中加入控件(部分),列表如下:
菜单NAME:mnuPracticeCAPTION:Practice子菜单NAME:mnuStartCAPTION:Start Practice NAME:mnuPauseCAPTION:Pause Practice NAME:mnuResumeCAPTION:Resume Practice NAME:mnuCustomCAPTION:Custom Practice NAME:mnuRestartCAPTION:Restart Practice NAME:mnuExitCAPTION:Exit状态栏NAME:Stautsbar1 文本框NAME:Text1(0)INDEX:0TABSTOP:FALSEVISIBLE:FALSE标签 NAME:Label1(0) INDEX:0VISIBLE:FALSEBACKSTYLE:0图片NAME:Picture1TABSTOP:FALSE时钟NAME:Timer1INTERVAL:1000 ENABLED:FALSE对话框NAME:CommonDialog1 工具栏NAME:Toolbar1 (备注:文本框控件Text1(0)和Label1(0)放入Picture1控件中)
2) 加入如下代码:
(本文来源于图老师网站,更多请访问http://www.tulaoshi.com/vb/)rowcount是练习文本的行数,totalchar是练习文本的总字数
Dim rowcount, totalchar As Integer
mode是当前练习状态:start为正在联系,pause中止练习,否则为等待状态
filename为练习文本文件的文件名
Dim mode, filename As String
playsec为当前练习所用的秒数
Dim playsec As Long
------------------------------------------
Private Sub Form_Load()
Dim i As Integer
调整Picture1控件的位置
Picture1.Top = Toolbar1.Top + Toolbar1.Height + 10
Picture1.Height = Picture2.Top - Picture1.Top
显示当前练习状态
StatusBar1.Panels(1).Text = "Status : Waiting..."
End Sub
------------------------------------------
Private Sub Form_Unload(Cancel As Integer)
如果练习文本行数大于0,则将动态生成的输入文本框和标签控件卸载
If rowcount > 0 Then
Dim i As Integer
For i = 1 To rowcount
Unload Label1(i)
Unload Text1(i)
Next
End If
End Sub
---------------------------------------------------------
Private Sub mnuCustom_Click() 自定义练习内容
On Error GoTo Error_Exit
弹出练习文本文件选择框
CommonDialog1.ShowOpen
如果选择的文件名为空,则退出
If CommonDialog1.filename = "" Then Exit Sub
如果当前练习状态不是等待状态,则停止当前练习
Timer1.Enabled = False
playsec = 0
Dim i As Integer
For i = 1 To rowcount
Unload Label1(i)
Unload Text1(i)
Next
filename = CommonDialog1.filename
开始新的练习,练习文本为用户选择的文本文件
Call mnuStart_Click
Exit Sub
Error_Exit:
Exit Sub
End Sub
------------------------------------------
Private Sub mnuExit_Click() 退出程序
Timer1.Enabled = False
Unload Me
End Sub
--------------------------------