首先将要滚动显示的文字赋给一个字符串变量(设为str),假设在lable控件上显示这些文字,在timer_tick中用如下代码:
static i as int16
if i<str.length then
lable.text=str.substring(0,i)
i+=1
else
i=0
end if
如果不想窗体一装载就开始显示,那直接这样:
Private Sub Form_Load()
Timer1.Interval = 50
starTime = GetTickCount
i = 1
Label1.Caption = ""
End Sub
Private Sub Timer1_Timer()
Dim strTip As String
strTip = "你挂啦!哈哈!"
If (GetTickCount - starTime) > i * 1000 Then
Label1.Caption = Label1.Caption & Mid(strTip, i, 1)
i = i + 1
End If
End Sub
改进:
Private Declare Function GetTickCount Lib "kernel32" () As Long
Dim starTime As Long, i As Long
Private Sub Command1_Click()
Timer1.Interval = 50
starTime = GetTickCount
i = 1
Timer1.Enabled = True
End Sub
Private Sub Form_Load()
Timer1.Enabled = False
Label1.Caption = ""
End Sub
Private Sub Timer1_Timer()
Dim strTip As String
strTip = "你挂啦!哈哈!"
If (GetTickCount - starTime) > i * 1000 Then
Label1.Caption = Label1.Caption & Mid(strTip, i, 1)
i = i + 1
End If
End Sub
Private Declare Function GetTickCount Lib "kernel32" () As Long
Dim starTime As Long
Private Sub Command1_Click()
Timer1.Interval = 1000
Timer1.Enabled = True
starTime = GetTickCount
Label1.Caption = "你"
End Sub
Private Sub Form_Load()
Timer1.Enabled = False
End Sub
Private Sub Timer1_Timer()
If (GetTickCount - starTime) > 1000 Then
Label1.Caption = "你挂"
End If
If (GetTickCount - starTime) > 2000 Then
Label1.Caption = "你挂啦"
End If
If (GetTickCount - starTime) > 3000 Then
Label1.Caption = "你挂啦!哈"
End If
If (GetTickCount - starTime) > 4000 Then
Label1.Caption = "你挂啦!哈哈!"
End If
End Sub