-1
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick

    If Label1.Text.Length = 13 Then
        Label1.Text = "Working magic."
    ElseIf Label1.Text.Length = 14 Then
        Label1.Text = "Working magic.."
    ElseIf Label1.Text.Length = 15 Then
        Label1.Text = "Working magic..."
    ElseIf Label1.Text.Length = 16 Then
        Label1.Text = "Working magic"
    End If

End Sub

该代码基本上充当一个渐进式字符串,每 500 毫秒一个点将添加到字符串中,直到 3 个点重置。

如果我想做更多的点,那么自动化这个过程会很好,而不是编写无数行代码。

4

6 回答 6

2

If you want to shorten your code you could do something like this:

Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
        (Label1.text += ".").Replace("....","")
End Sub

However I'm convinced that shorter is not always better!

Edit: Sorry my mind goes straight to c#, here is some VB::

Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
         Label1.text = (Label1.text + ".").Replace("....","")            
End Sub
于 2013-09-04T23:05:12.390 回答
2

伪代码:

len = Label1.Text.Length - 12
str = "Working magic"

while(len>0 && len<4){
    str = str & "."
    len--;
}
Label1.Text = str
于 2013-09-04T22:49:53.430 回答
1

考虑到一行中可变点数的伪代码。

final NUM_DOTS = 3  //this is your variable number of dots
len = Label1.Text.Length - 12
str = "Working magic"
numDots = NUM_DOTS

while(len){
    if (numDots == 0) {
        str = str.substring(0, str.length-NUM_DOTS);
        numDots = NUM_DOTS;
    }
    else {
        str = str & "."
        len--;
        numDots--;
    }
}
Label1.Text = str
于 2013-09-04T22:56:01.327 回答
1

考虑使用像这里生成的动画 GIF:http ://www.ajaxload.info/

尝试 Google 搜索以获取更多选项:“动画 gif 生成器”

只需使用图片框中的 GIF 并使用 .Enable/.Visible 进行管理。

如果主线程很忙,动画可能会停止 - 对于上述情况也可能如此。

于 2013-09-04T23:52:39.807 回答
1

简单的控制台应用程序演示

Module Module1

   Sub Main()
    Console.WriteLine(Magic(New String("A"c, 13).Length))
    Console.WriteLine(Magic(New String("A"c, 14).Length))
    Console.WriteLine(Magic(New String("A"c, 15).Length))
    Console.WriteLine(Magic(New String("A"c, 16).Length))
    Console.Read()

End Sub

Private Function Magic(ByVal len As Integer) As String
    Dim result = "Working magic"
    Select Case len
        Case 13 To 15
            result = result & New String("."c, len - 12)
    End Select

    Return result
End Function

End Module
于 2013-09-04T23:08:36.950 回答
0

将要打印的点数保留为全局变量,然后在每次调用计时器事件时递增此值,并在达到上限时将其重置。

根据当前计数创建一串点并将其附加到静态标签

Private dotCount As Integer = 0
Const MAX_DOTS = 3 


Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
    if dotCount > MAX_DOTS Then
        dotCount = 0
    End If
    Label1.Text = "Working magic" & new String(".", dotCount)
    dotCount = dotCount + 1
End Sub

如果要打印更多点,只需更改用作上限的常量(MAX_DOTS)

于 2013-09-04T22:59:21.637 回答