Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>By default, the Splash screen stays open for two seconds, or longer if the "Startup Form" takes longer than that to "load".</p> <p>Therefore, to make your splash screen stay open for however long you need, simply <strong>block</strong> the main form from loading until it is signaled. One way to do this is with a ManualResetEvent.</p> <p>In this setup, the "Startup form" is <code>Form1</code>, the "Splash screen" is <code>Splash</code>, and "Shutdown mode" is <code>When startup form closes</code>.</p> <p>In Splash, I've added a Shared ManualResetEvent and only signal it when the form is done animating:</p> <pre><code>Public Class Splash Private appearance As Boolean = False Public Shared MRE As New System.Threading.ManualResetEvent(False) Private Sub Splash_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Opacity = 0 FadeIn.Start() End Sub Private Sub FadeIn_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FadeIn.Tick If Not appearance Then Opacity += 0.015 Else Opacity -= 0.015 End If If Opacity = 1 Then appearance = True ElseIf Opacity = 0 Then MRE.Set() End If End Sub End Class </code></pre> <p>Now, over in Form1, we call WaitOne() against the Shared ManualResetEvent:</p> <pre><code>Public Class Form1 Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load Dim MySplash As Splash = DirectCast(My.Application.SplashScreen, Splash) Splash.MRE.WaitOne() ' wait for the splash to signal ' ... other code ... End Sub End Class </code></pre> <p>Now Form1 one will not appear until the splash screen is done animating, <strong>and</strong> the application will properly have Form1 as the "Startup form" so it won't shutdown when splash closes and Form1 opens. Also note that we are not explicitly opening or closing any forms in the code; that is done automatically for us by the framework itself.</p> <p>With this approach the main form won't open until the splash screen is done. Furthermore, if you change the animation length, you won't have to go in and change MinimumSplashScreenDisplayTime() as there is no guesswork involved.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload