0

我在 VB.Net 中创建了一个启动画面,并且一切正常,除了我想用多个文本更改加载文本,这些文本在加载过程中每 x 秒更改一次。

加载文本

例子:Dim LoadingTexts As String = {"charging 1...", "charging 2...", "info1..."}

我不知道我怎么能做到这一点,除了我肯定必须使用计时器......但是怎么做呢?

实际代码:

Public Class frmSplashScreen
   Private stringTable() As String = {"Shovelling coal into the server...", "Programming the flux capacitor...", _
                                      "Searching for answer to live, the universe and everything...",
                                      "Waiting for Godot...", "Starting..."}
   Private stringMove As Integer = 0

    Sub New()
        InitializeComponent()
    End Sub

    Public Overrides Sub ProcessCommand(ByVal cmd As System.Enum, ByVal arg As Object)
        MyBase.ProcessCommand(cmd, arg)
    End Sub

    Public Enum SplashScreenCommand
        SomeCommandId
    End Enum

    Public Sub SplashTimer_Tick(sender As Object, e As EventArgs) Handles SplashTimer.Tick
        Me.SplashTimer.Enabled = False

        Me.labelStarting.Text = stringTable(stringMove)
        Me.labelStarting.Refresh()

        stringMove += 1
        If stringMove < stringTable.Length Then Me.SplashTimer.Enabled = True
    End Sub
End Class

谢谢。

4

2 回答 2

3

假设您有一个计时器、进度条、按钮和标签,进度条的步长值设置为 10,您的代码可能如下所示:

Public Class Form1

Private Sub butStart_Click(sender As System.Object, e As System.EventArgs) Handles butStart.Click
    Timer1.Enabled = True
End Sub

Private Sub Timer1_Tick(sender As System.Object, e As System.EventArgs) Handles Timer1.Tick
    ProgressBar1.Increment(ProgressBar1.Step) 'use method below as well
    'ProgressBar1.Value+=ProgressBar1.Step


    Me.Refresh()

    If ProgressBar1.Value >= 0 AndAlso ProgressBar1.Value < 35 Then
        Label1.Text = ProgressBar1.Value & "% Starting"
        Me.Refresh()
    ElseIf ProgressBar1.Value >= 35 AndAlso ProgressBar1.Value < 75 Then
        Label1.Text = ProgressBar1.Value & "% Mid value"
        Me.Refresh()
    ElseIf ProgressBar1.Value >= 75 AndAlso ProgressBar1.Value < 100 Then
        Label1.Text = ProgressBar1.Value & "% Finishing"
        Me.Refresh()
    ElseIf ProgressBar1.Value = 100 Then
        Timer1.Enabled = False
        'Move to next form or something
    End If
End Sub

End Class

于 2013-08-26T18:26:23.917 回答
1

如果需要每 X 秒更改一次,请使用 Timer。更改.Text标签的属性:

Dim iLoadText As Integer = 0

Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
    Timer1.Enabled = False

    Label1.Text = LoadingTexts(iLoadText)
    Label1.Refresh()

    iLoadText += 1
    If iLoadText < LoadingTexts.Length Then Timer1.Enabled = True
End Sub
于 2013-08-26T14:27:25.160 回答