How can I show a splash form while my application loads? You know, I want it to be shown right after the running of program not as the first form of the program.
Printable View
How can I show a splash form while my application loads? You know, I want it to be shown right after the running of program not as the first form of the program.
I definately think that opacity is the best solution for this. In the form load event of your main form put this:-
VB Code:
Me.Opacity = 0 Dim frmSplash As New splash() frmSplash.Show() 'put initializing code here or a delay of some kind frmSplash.Close() Me.Opacity = 1 Me.Show()
then in the splash form's load event put this:-
Me.Show()
Me.Refresh() 'if you have any buttons or progress bars the refresh is needed.
Thanks for your help, but i guess I couldnt convey exactly what i mean. You know usually on slow machines it takes a considerable time for a large application to load and run. I want the splash form to be shown in this period of time, but your code provieds a way of showing a splash form after the main form is loaded.
Yes it does - I have indicated where you should place any code that has to run procedures that will take some time.
You have to load your main form first. This is the way .net apps work.
If you place any intensive code where I suggest then the splash should be visible while you do this code.
Maybe I am dumb, but i think there is no such type in .NET called 'splash', so maybe you mean 'New form()'
Thanks,
I used following code and it works fine. I put the code before and after initialization of form components.
Public Sub New()
MyBase.New()
Me.Opacity = 0
Dim frmsplash As New Form2()
frmsplash.Show()
'This call is required by the Windows Form Designer.
InitializeComponent()
frmsplash.Close()
Me.Opacity = 1
'Add any initialization after the InitializeComponent() call
End Sub
Do you think its a proper place to put the code?
Where are you actually having the slow loading comming from? What I mean by that is there is two ways your forms can be slow loading.
The first way, is right after you compile (build) your app to MSIL, the JIT compiler will then need to convert your app from MSIL to binary. This should only be the first time it is ran though. If you run it again after the first time, without rebuilding the solution, it should start up much faster.
The second way it can be slow, is if you have a form with a lot of controls on it. Assuming this is the second time you ran the app, not from the IDE, from the bin directory by double clicking the exe, and it is taking a while, then I would go with the above code posted by Lunatic3.
Sorry Splash() is just the name of the form I gave my splash form. I may be fussy but I like to call my forms by names that indicate what they are.
another way !Hope you like it :DCode:
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Me.Opacity += 0.1
If Me.Opacity = 1 Then
Button1.Visible = True
End If
End Sub
You might want to disable the timer when opacity gets to 1 too.
exactly what I thought . thanx for that .
Code:code
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Me.Opacity += 0.1
If Me.Opacity = 1 Then
Button1.Visible = True
Timer1.enabled = False
End If
End Sub