Share via


Splash Screens in VB 2005

One of the things we provided in the application model for VB is the ability to easily integrate a splash screen into your application. We take care of displaying it, making sure it displays for at least some user specifiable period of time, and taking it down once your application's main form is ready to display.

One of the things that throws people is how to set the minimum amount of time for the splash screen to display. Admittedly, we have some work to do to make this easier. 

For now, if you don't like the default two second minimum, you can specify your own minimum in milliseconds by overriding the OnInitialize method on the MyApplication class. Here's how you do it (and note that all of this presupposes that you have the application model enabled in the first place):

Go to the project designer by double-clicking the 'My Project' node in your solution. Once you've specified which form is to be your splash screen, click the View Application Events button. You'll see a MyApplication class inside the My namespace. Go in that class and add an override to OnInitiliaze like this:

Protected Overrides Function OnInitialize(ByVal commandLineArgs As System.Collections.ObjectModel.ReadOnlyCollection(Of String)) As Boolean
Me.MinimumSplashScreenDisplayTime = 5000
Return MyBase.OnInitialize(commandLineArgs)
End Function

Now the splash screen will stay up a minimum of five seconds.

The splash screen displays early on in your applications startup. The idea is to have that displaying until your main form is ready to display. Then we take it down unless you've specified a minimum 'face time' that you want for your splash screen. Once the minimum splash time expires we take the splash screen down. Just set it to zero if you want it taken down automatically once your main form has completed loading.

All of this exposes you to a variety of things going on behind the scenes. Next time I'll write about the application model and what the sequence of events is when an app that uses the new application model starts up.

Comments

  • Anonymous
    February 14, 2006
    The comment has been removed

  • Anonymous
    December 06, 2006
    very helpfull article.  Really shows some of the functionality for vs2005 thanks

  • Anonymous
    April 07, 2007
    I tried what he said in this article. When playing around i found that if you put a module to save a setting and inside the splash screen like Friend Module MyConfig Private __splashLoading As Boolean = True Public Property isSplashLoadingDone As Boolean Get   Return __splashLoading End Get Set(ByVal value As Boolean)  __splashLoading = value End Set End Property End Module Then inside your loading form under the load event use a loop  to loop tioll your loading procedures inside your splash screen finish like this after your loading procedures are done My.MyConfig.isSplashLoading = False In your form put Do While My.MyConfig.isSplashLoading = True Loop If that will be any help to anybody

  • Anonymous
    April 13, 2007
    The comment has been removed

  • Anonymous
    April 13, 2007
    I should add that even after the startup form is asked to close the splash screen still doesn't want to close. -- so I have to manually terminate the program

  • Anonymous
    April 13, 2007
    The comment has been removed

  • Anonymous
    April 16, 2007
    Thanks for your quick reply. The reason I am trying to close the form myself is because it won't close itself.  Even after I have closed the main (startup) form (clicking the x) myself the splash won't close... Peter

  • Anonymous
    April 25, 2007
    Do you think there could be a connection to windows 2000?

  • Anonymous
    May 01, 2007
    Mysterious.  No, this works just fine on Windows 2000.  I just gave it a whirl. You are following the instructions from my post, right?  There is no funky shutdown code in your splash screen that is stopping it from closing?  Does your main form or splash form have any interesting code running when it loads?

  • Anonymous
    August 01, 2007
    I'm fighting with a problem with my splashscreen: when the application starts, it shows the splash, then it closes and the main form shows.... ok ! But the mainform is not the active window. It doesn't have the focus. How to solve it ? I'm thinking not to use the My.Splashcreen feature anymore...

  • Anonymous
    August 07, 2007
    Sorry for the delay.  I've been out of the office for awhile. There is a way around this, but it is really rather involved.  I will try to write up how to do it and post it in the next few days. What currently happens is that after the splash screen is closed we make a call to set the main form to Active, which is what doesn't work in your scenario.  Unfortunately there isn’t an easy way to override this behavior.  With some gymnastics it can be done, but it isn't pretty. I've entered a work item for myself to consider for the next release that will make this case much easier.  I can't guarantee that we'll do it (it always depends on schedule pressure and what else is going on for a release) but I'd like to get to it.

  • Anonymous
    August 07, 2007
    Thank you Tyler ! I found out that if I click with mouse on the Splash screen, when it shows up, after then the Mainform gets the focus...

  • Anonymous
    August 08, 2007
    I finally resolved this problem with this (don't know why, delay time I suppose) : Protected Overloads Overrides Sub OnCreateSplashScreen() Me.SplashScreen = My.Forms.FormSplash For i As Integer = 0 To 100 My.Forms.FormSplash.Opacity = i Next End Sub

  • Anonymous
    September 08, 2007
    I have a rather ridiculous problem ... while my splash screen is being displayed, its is supposed to be reading file extensions from the registry, it goes on fine for a few seconds, but then the main form shows up before the process is finished and the splash screen disappears. I have tried after making the minimum time higher but that doesn't do any good either ... Is there anything wrong in my code or something? Here is the code in the splash screen: Public NotInheritable Class splash    Dim reg(100000) As String    Private Sub splash_Shown(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Shown        My.Computer.Registry.ClassesRoot.GetSubKeyNames.CopyTo(reg, 0)        My.Application.DoEvents()        Dim i As Integer        Dim count As Integer = 0        For i = 0 To 100000            If reg(i) = "" Then                Exit For            Else                If reg(i).Chars(0) = "." Then                    lab.Text = reg(i)                    count += 1                    My.Application.DoEvents()                End If            End If        Next        MsgBox(count)    End Sub End Class


  • "lab" is the label on the splash screen, acting as a feedback ...
  • variable "count" was used while i was finding the error
  • file extensions are stored in HKEY_CLASSES_ROOT in the registry

Thanks for reading this, Imran

  • Anonymous
    July 24, 2008
    is it possible to display the splash screen until MainForm's OnLoad method finishes? it looks like the splash form is closed or hide before OnLoad method. Thanks.

  • Anonymous
    July 30, 2008
    The comment has been removed

  • Anonymous
    July 30, 2008
    Hi Imran, Two variables govern how long the splash screen stays up.  If no minimum time-out for the splash screen is specified, the splash closes when the startup form's Load event (e.g. when Form1_Load() handles mybase.Load) returns. If you do specifiy a minimum time-out (see post above on how to do that), then the splash closes when two things are true: the startup form's load event has returned AND the timeout has expired. But there may be a better way than trying to arrive at a good delay time for the splash screen.  What might work is to put your file extension loading code in the startup form's load handler (e.g. Form1_Load()... ) so that the splash screen doesn't close until the main form's load is finished. There are quite a number of things I'd like to do to the Splash screen plumbing to make things like this easier in the future.  I'll have to see if I can do any moonlighting on the runtime during the next cycle that they are doing work in this area.

  • Anonymous
    June 01, 2009
    PingBack from http://woodtvstand.info/story.php?id=5544

  • Anonymous
    June 02, 2009
    PingBack from http://woodtvstand.info/story.php?id=46732

  • Anonymous
    June 19, 2009
    PingBack from http://mydebtconsolidator.info/story.php?id=18926