Transparent Splash screen in .Net

To give a nice look at your applications there are a lot of little thing that makes the difference. One of that is a nice Splash screen like the one of Photoshop or other famous software. Making it in VB.Net is really simple, all that you need is:

  • A nice image to use as splash screen
    In our case we want a transparent image so we’ll save it in PNG format to take transparency.
    We’ll use the image as embedded resource in our project
  • A form that paints the image on it’s background
  • A timer to close the splash screen after 4 seconds

In this demo project we’ll create a main form that acts this way:

  • When the form loads it hides itself
    Simply use Me.Visible=false
  • Then it creates the SplashScreen and displays it as modal form
  • When the splash screen closes just show itself again

Here is the image we’ll use as splash screen (made with photoshop)

Splash screen made with Photoshop

Here is the code to write into the Splash screen Form

Private imgSplash As System.Drawing.Image = _
     System.Drawing.Image.FromStream( _
          GetResource("Splash Screen.png"))
 
Private Shared m_Assembly As System.Reflection.Assembly =_
     System.Reflection.Assembly.GetExecutingAssembly()
Private Shared m_AssemblyPath As String = _
     m_Assembly.GetName().Name().Replace(" ", "_")
 
Public Shared Function GetResource(ByVal FileName As String) _
       As System.IO.Stream
    Return m_Assembly.GetManifestResourceStream(m_AssemblyPath _
       & "." & FileName)
End Function
 
Protected Overrides Sub OnPaintBackground(ByVal pevent As _
          System.Windows.Forms.PaintEventArgs)
    Dim gfx As dra.Graphics = pevent.Graphics
    gfx.DrawImage(imgSplash, New dra.Rectangle(0, 0, _
        Me.Width, Me.Height))
End Sub
 
Private Sub SplashScreen_Load(ByVal sender As System.Object, _
               ByVal e As System.EventArgs) Handles MyBase.Load
    T1.Enabled = True
    T1.Start()
End Sub
 
Private Sub T1_Tick(ByVal sender As System.Object, _
         ByVal e As System.EventArgs) Handles T1.Tick
    T1.Stop()
    T1.Dispose()
    Me.Close()
End Sub
 
Protected Overrides Sub OnClick(ByVal e As System.EventArgs)
    T1.Stop()
    T1.Dispose()
    Me.Close()
End Sub

Download this code: Splashscreen.vb.txt

And this is the final result

Splash screen in action
Download the demo application source code here
Splash Screen demo application



Leave a Reply