hbqjxhw 发表于 2006-8-9 20:16:09

如何实现文本动态显示

在窗体上添加两个计时器,设置Timer1的属性:Interval=200,设置Timer2的属性:Enabled=False,interval=5000

'如何实现文本动态显示
Dim l As Integer, i As Integer, x As Integer, y As Integer
Dim page As Integer
Dim filenum As Integer
Dim words As String
Private Sub form_load()

ChDrive App.Path
ChDir App.Path
FileName$ = "c:\text.txt"
filenum = FreeFile
Open FileName$ For Input As #filenum
Do While Not EOF(filenum)
Line Input #filenum, Text$
words = words + Text$ + Chr(13) + Chr(10) '将文本内容赋值给words串变量,包括回车符和换行符
Loop
Close #filenum
l = Len(words) '计算words串变量长度(字符个数)
End Sub

Private Sub Timer1_Timer()
If page = 1 Then '满一页后清除窗体内容
Form1.Cls
page = 0
Timer1.Interval = 200 '重置打字速度
End If
typewrite '调用打字子例程
End Sub
Public Sub typewrite()
i = i + 1 '字符计数器
x = x + 1
CurrentX = 100 '设置打字的起始点
CurrentY = 300
CurrentX = CurrentX + x * 250 '设置字间距
CurrentY = CurrentY + y * 280 '设置行间距
t$ = Mid$(words, i, 1) '从words串中指定位置取一个汉字或标点符号
Print t$ '在窗体上打印一个字符
If x = 20 Or Mid$(words, i, 2) = Chr$(13) + Chr$(10) Then '设置行字符个数,若行字数满或段落结束(遇回车换行符)则换行
y = y + 1
x = 0
End If
If y = 12 Then '设置行数
page = 1 '行数满为一页
y = 0
Timer1.Interval = 6000 '设置页显示停留时间
End If
If i > l Then '文本内容打印完毕,计时器2打开
Timer1.Enabled = False
Timer2.Enabled = True
End If
End Sub

Private Sub Timer2_Timer()
Timer2.Enabled = False
Timer2.Enabled = False
End '改变END,可执行其它子例程
End Sub

刚学习VB编程,大家有什么好的程序,好的看法还请跟贴讨论。(在这里向大家学习了)

caterpilla 发表于 2006-8-9 22:28:51

支持。。。。。
不过在运行时是否有窗口闪动的情况?
页: [1]
查看完整版本: 如何实现文本动态显示