Creating a by letter effect with visual studio

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-24 16:25:04

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!