Private Sub MyApplication_Startup(ByVal sender As Object, ByVal e As Microsoft.VisualBasic.ApplicationServices.StartupEventArgs) Handles Me.Startup
' Get the splash screen.
Dim splash As SplashScreen1 = CType(My.Application.SplashScreen, SplashScreen1)
' Display current status information.
splash.Status = "Current user: " & My.User.Name
End Sub
Delegate Sub SetTextCallback([text] As String)
Private Sub SetText(ByVal [text] As String)
If Me.textBox1.InvokeRequired Then
Dim d As New SetTextCallback(AddressOf SetText)
Me.Invoke(d, New Object() {[text]})
Else
Me.textBox1.Text = [text]
End If
End Sub
Public Class frmSplashScreen
Private Delegate Sub UpdateProgressDelegate(ByVal msg As String, ByVal percentage As Integer)
Public Sub UpdateProgress(ByVal msg As String, ByVal percentage As Integer)
If Me.InvokeRequired Then
Me.Invoke(New UpdateProgressDelegate(AddressOf UpdateProgress), New Object() {msg, percentage})
Else
Me.Label1.Text = msg
If percentage >= Me.ProgressBar1.Minimum AndAlso percentage <= Me.ProgressBar1.Maximum Then
Me.ProgressBar1.Value = percentage
End If
End If
End Sub
Private Sub frmSplashScreen_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
' Draw a Black Border around the Borderless Form:
Dim rc As New Rectangle(0, 0, Me.ClientRectangle.Width - 1, Me.ClientRectangle.Height - 1)
e.Graphics.DrawRectangle(Pens.Black, rc)
End Sub
End Class
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim splash As frmSplashScreen = CType(My.Application.SplashScreen, frmSplashScreen)
Dim MadeUpSteps() As String = {"Initializing...", "Authenticating...", "Retrieving Widgets...", "Loading Components...", "Updating Doomahickies..."}
For i As Integer = 0 To MadeUpSteps.Length - 1
splash.UpdateProgress(MadeUpSteps(i), CInt((i + 1) / MadeUpSteps.Length * 100))
System.Threading.Thread.Sleep(1500)
Next
End Sub
End Class
Have a question about something in this article? You can receive help directly from the article author. Sign up for a free trial to get started.
Comments (17)
Commented:
Thank you for the article, an excellent example and what I need for my application.
My question now becomes, how can I determine what is occurring in my application prior to the formMain_Load() event being triggered? The splash screen is visible and active for 15 seconds prior to reaching the breakpoint at the first line of the MyBase.Load event of formMain. Afterwards, everything is as expected. What is happening during this time prior to the main form getting loaded? Any information is greatly appreciated. Thank you for your time and help.
Christopher
Commented:
But I have a similar but different scenario with a common problem: We have a DLL that has inbuilt forms that provide tools to manage user preferences. A lot of data is loaded when instantiating some classes in the DLL, so I wanted to create an embedded SplashScreen form (within the DLL) that can be called by processes that take a while to load. Of course, I found out that the Application.SplashScreen feature (in Project.Properties) is NOT available in a DLL (disabled).
So, inside the DLL, I created a borderless form (SplashScreen_PLM) which has a label (lblMessageText), a progressbar, and a Timer control. The timer control was set to 100ms, and upon firing it would increment the progressbar value by 1, update the label with "Please wait..." & progressbar.value, by calling a routine that implements my version of your CallBack delegate routine (see code below).
Upon loading a form internal to the DLL, I instantiate an instance of SplashScreen_PLM (form), .Show() it, load the desired form, and close the SplashScreen_PLM form after loaded.
The loading and unloading of the splash form works just fine, but the problem is that the ProgressBar and Label do not update!
(When loading the splash form from outside the DLL, by itself, the progress bar and label update as it should.)
Any thoughts or suggestions will be welcome. Thank you!
Public Class SplashScreenPLM
Inherits Windows.Forms.Form
Private Delegate Sub SetTextCallback([text] As String)
Private Sub SetText([text] As String)
If Me.InvokeRequired Then
Dim d As New SetTextCallback(AddressOf SetText)
Me.Invoke(d, New Object() {[text]})
Else
lblMessageText.Text = "Please wait ... " & [text]
ProgressBar1.Increment(1)
If ProgressBar1.Value >= ProgressBar1.Maximum Then
ProgressBar1.Value = 0
End If
Application.DoEvents()
End If
End Sub
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
SetText(ProgressBar1.Value
End Sub
Private Sub SplashScreenPLM_Load(sende
Timer1.Enabled = True
Timer1.Start()
End Sub
End Class
Commented:
Open in new window
Or use backgroundworker to start splashCommented:
Thanks all the same, everyone!
Commented:
I'm trying to use your code in windows app.
It is working as described, but I'm having Login form in my Main Form Load event and
when Login form opend it is not active.
What could be done to reslove this isue.
Thank you for asistance (if this post comes to you)
View More