问题
I would like to create an effect in visual studio where text shows up on the screen not all at once, but letter by letter with a certain amount of time between each letter appearing. I plan to open a different module that will have this code in it from my main module. Any ideas? Here is my coding so far. I am making a command prompt.
Public Sub Main()
Dim line As String
Console.Title = "Command"
Console.WriteLine("Microsoft Windows [Version 6.3.9600]")
Console.WriteLine("<c> 2013 Microsoft Corporation. All right reserved.")
Console.WriteLine(" ")
Do
Console.Write("C:\Users\Bob>")
Line = Console.ReadLine()
If line = "help" Then
Console.WriteLine("hello world")
Console.WriteLine(" ")
ElseIf line = "help1" Then
Console.WriteLine("hello again, world!")
Console.WriteLine(" ")
ElseIf line = "exit" Then
Environment.Exit(0)
Else
Console.WriteLine("Command not found.")
Console.WriteLine(" ")
End If
Loop While line IsNot Nothing
End Sub
回答1:
Just replace all of your Console.WriteLine
with Marquee("Text here")
Update: As Walt points out in the comments it should be noted this approach will lock up the application until the text has finished displaying. If this is not desired then you should think about offloading it to another thread or creating a timer event.
Sub Main()
Marquee("Hello World")
Console.ReadLine()
End Sub
Sub Marquee(StringToWrite As String)
For i As Integer = 0 To StringToWrite.Length - 1
Console.Write(StringToWrite.Substring(i, 1))
Threading.Thread.Sleep(200)
Next
End Sub
回答2:
For a windows form app, my best shot is this:
Public Class Form1
Dim M As Integer = 1
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
Dim T As String = "" + TextBox1.Text
Label1.Text = Label1.Text + Mid(T, M, 1)
M = M + 1
End Sub
'You can use any trigger here
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Timer1.Enabled = True
End Sub
End Class
来源:https://stackoverflow.com/questions/21057557/creating-a-by-letter-effect-with-visual-studio