在vb中如何编一个代码实现模拟把文字一个一个显示出来,可以调剂快慢
“文字一个一个显示出来”可能有两种理解:一是像打字那样的效果,一个“接”一个地显示;二是显示当前字的时候刚刚显示的消失,就是一个代替一个地显示。
Dim i As Integer
Dim L As Integer
Dim v As Integer
Private Sub Command1_Click()
i = 0
L = Len(Text1.Text)
'方法一:用text输入速度值,缺点:输入必须大于0,且必须不能输入数字以外的
v = Text2.Text * 1 '设置速度,单位为毫秒,乘1是强制转换为数字
Timer1.Interval = v
Timer1.Enabled = True
End Sub
Private Sub HScroll1_Change()
'方法二:用滚动条控制速度,缺点:有上下限的局限
v = HScroll1.Value
End Sub
Private Sub Text2_Change() '输入的有效性
If IsNumeric(Text2.Text) And Text2.Text <> "0" Then
v = Text2.Text * 1
Else
MsgBox "请输入大于0的数字!"
Text2.Text = 500
End If
End Sub
Private Sub Timer1_Timer() '动态效果
Timer1.Interval = v '用于改变速度
i = i + 1 '下一个字符
showWord.Caption = Left(Text1.Text, i)
If i = L Then Timer1.Enabled = False '必须的,否则出错
End Sub
我知道了 谢谢
插入时间控件和一个标签
你可以在Timer1.Interval中调节快慢
Private Sub Form_Load()
Timer1.Interval = 1000
End Sub
Private Sub Timer1_Timer()
Dim i As String
i = Label1.Caption
Label1.Caption = "你"
Select Case Len(i)
Case 1
i = "你会"
Label1.Caption = "你会"
Case 2
i = "你会进"
Label1.Caption = "你会进"
Case 3
i = "你会进步"
Label1.Caption = "你会进步"
Case 4
i = "你会进步,一"
Label1.Caption = "你会进步,一"
Case 6
i = "你会进步,一步"
Label1.Caption = "你会进步,一步"
Case 7
i = "你会进步,一步,一"
Label1.Caption = "你会进步,一步,一"
Case 9
i = "你会进步,一步,一步"
Label1.Caption = "你会进步,一步,一步"
Case 10
i = "你会进步,一步,一步,相"
Label1.Caption = "你会进步,一步,一步,相"
Case 12
i = "你会进步,一步,一步,相信"
Label1.Caption = "你会进步,一步,一步,相信"
Case 13
i = "你会进步,一步,一步,相信自"
Label1.Caption = "你会进步,一步,一步,相信自"
Case 14
i = "你会进步,一步,一步,相信自己"
Label1.Caption = "你会进步,一步,一步,相信自己"
Case 15
i = "你会进步,一步,一步,相信自己!"
Label1.Caption = "你会进步,一步,一步,相信自己!"
End Select
If Len(i) = 16 Then
Timer1.Enabled = False
End If
End Sub
你自己运行下看看符不符合你的要求!
我的意思是 我们输入一段话 然后按指定的速度(或可以调速)来把字显示出来
这是借鉴三楼的兄台:
Dim ss As String, i As Integer
Private Sub Form_Load()
HScroll1.Min = 40
HScroll1.Max = 2000
HScroll1.LargeChange = 100
HScroll1.SmallChange = 50
Do While Len(Label1.Caption) < Len(ss)
Timer1_Timer
Loop
End Sub
Private Sub HScroll1_Change()
Timer1.Interval = HScroll1.Value
End Sub
Private Sub Timer1_Timer()
ss = Text1.Text
i = i + 1
Label1.Caption = Left(ss, i)
End Sub
现在只能到这种效果,只能查看一次!
这样:计时器1个(timer1),文本框(text1)一个
代码:
Dim E As String
Private Sub Form_Load()
Dim i As Double
Randomize
For i = 1 To 9
E = E & CStr(Rnd * 1000)
Next i
Timer1.Interval = 1
Timer1.Enabled = True
Text1.Text = ""
End Sub
Private Sub Timer1_Timer()
If Len(E) >= 1 Then
Text1.Text = Text1.Text & Left(E, 1)
E = Right(E, Len(E) - 1)
End If
End Sub
速度可以调interval
他不能运行啊
这个,不可能把。我调试的是好的,可以发上错误图啊。
以下代码提供参考:
Dim ss As String, i As Integer
Private Sub Form_Load()
ss = "abcdefghijklmnopqistuvwxyz"
Timer1.Enabled = True
HScroll1.Min = 200
HScroll1.Max = 800
End Sub
Private Sub HScroll1_Change()
Timer1.Interval = HScroll1.Value
End Sub
Private Sub Timer1_Timer()
i = i + 1
If i = Len(ss) Then i = 1
Label1.Caption = Left(ss, i)
End Sub
能不能加上一张图啊,还有ScrollBar事什么控件啊?我找不到啊
HScrollBar,控件栏左起向下第6个。