Hi,
How can I make a splash screen fade in, pause for a given seconds, fade out then call an application?
Actually, I have made a splash screen fade in and fade out using a sample code I got from the net but I cannot make it pause....
Printable View
Hi,
How can I make a splash screen fade in, pause for a given seconds, fade out then call an application?
Actually, I have made a splash screen fade in and fade out using a sample code I got from the net but I cannot make it pause....
I would use a form. Remove the top bar and then use a timer to set its opacity. When it's at 100%, use the timer to wait like 5 seconds or so, then fade it back out.
You can make a form fade in and out using a Timer but, in my opinion, it is better to use the AnimateWindow API. I have made a submission in the VB.NET CodeBank (see my sig) that does just that. Using that method you can simply Start a Timer in the form's Load event handler with the desired Interval, then in the Timer's Tick event handler you would call Me.Close. It's that easy. If you want to use a Timer and the form's Opacity property to handle the fading, here's a code sample that uses a single Timer to fade in, pause, then fade out.VB Code:
Private loaded As Boolean = False Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Me.Opacity = 0.0 Me.Timer1.Interval = 50 Me.Timer1.Start() End Sub Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick If loaded Then 'The form is being faded out. Me.Opacity -= 0.05 Me.Timer1.Interval = 50 'In case we have just finished pausing. If Me.Opacity <= 0.0 Then Me.Close() End If Else 'The form is being faded in. Me.Opacity += 0.05 If Me.Opacity >= 1.0 Then Me.loaded = True 'Pause for 10 seconds. Me.Timer1.Interval = 10000 End If End If End Sub
Thanks jmcilhinney! The code works great! One problem though.....
I have a form that suppose to call my splash screen. So when I use:
Dim fsplash As New frmsplash
fsplash.Show()
Me.Close() 'This closes the originating form that calls the Splash Screen
The whole program closes that it was not able to show the Splash Screen. I also tried the Me.Hide() but the form only stays on the background while displaying the splash screen....
You'll want Application.Run() then for the Splash Screen.
Application.Run() for my splash screen?
My splashscreen and the form that calls it are on the same project....can you give me a sample?
http://www.google.com/search?client=...utf-8&oe=utf-8
First hit on Google.
VB Code:
Application.Run(New Form1())
Thanks kasracer...however, when I put the code Application.Run(fsplash), the program gives an error and suggests that I use the .ShowDialog instead.
When I used the fsplash.ShowDialog, my originating form does not show anymore and the splash screen was displayed. After the splash screen fades out it will call another form. Another error is flashed telling me that I should set the form.visible to false..
I think by doing this, this will consume resources since the originating form was not unloaded....what to do?
Are you using VB.Net 2003 or 2005?
* Take a module in your form - say modMain
* Add a Sub Main into it. Set it as a startup object in your Project properties.
* Write the following code in Sub Main
VB Code:
Sub Main() Dim frmSplash as new frmSplash frmSplash.ShowDialog() frmSplash.Dispose() Application.Run(frmMain) 'Show your main form End Sub
Hope it works
____________________________
If your problem is solved...add [RESOLVED] to the title
Dont forget to rate the post ;)
I'm using VB.NET 2003....
Thanks pvbangera! I'll give it a try....
If you're going to use ShowDialog then there isn't a specific need to use a Main method. Just create and Show the splash screen in the Load event handler of the main form.
Ok, here's what I did....
fsplash.ShowDialog()
Me.Dispose()
And I think it works the way I wanted it to...
Thanks a lot guys! All your help is very much appreciated!
I am still waiting for my post to be rated :-w ;)
Ok, got your post rated.....again thanks very much!!
Don't ask for ratings or the mods/admins will give you negative ratings.Quote:
Originally Posted by pvbangera
Just fyi