Reputation: 197
I have created a splashscreen in VB.Net and everythings works perfect except the fact that I would like to change the loading text with multiple texts who changes every x seconds during the loading.
Exemple : Dim LoadingTexts As String = {"charging 1...", "charging 2...", "info1..."}
I have no idea how i can do this apart the fact that i surely have to use a timer... But how ?
Actual code:
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
Thanks.
Upvotes: 0
Views: 1804
Reputation: 1709
Assuming you have a timer,progress bar,button and label,with the progress bar's step value set to 10,your code may look something like this:
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
Upvotes: 3
Reputation: 9888
If it needs to change every X seconds, then use a Timer. Change the .Text
property of the label:
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
Upvotes: 1