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


TAGS: Asp.net, dotnet, code snippet, seo, search engine optimization, visual studio.net, sample code, c#, vb.net

5 Comments so far »

  1. flo said

    am October 8 2007 @ 7:54 am

    for coding this is useful

  2. Alex said

    am November 18 2007 @ 4:11 am

    Im using your code, but have comment out the timer code, as I want the form to disappear when the initial form has loaded. But once in a while I get a dispose error, Im not sure why. Im doing it this way as Im showing information of what the application is doing while loading (like checking the sql server connection). Do u got any idea what it could be wrong??

  3. pippo said

    am November 27 2007 @ 11:50 pm

    Hi:)

    Excuse my English: P

    They are 2 weeks I try to set this effect on a simple form.

    I tried this code on a simple form … But it works

    When you move the form, remains imprinted what was behind the form.

    How do I do? You ask why not fail to find the solution :(

    Ok, thank you :)

  4. pippo said

    am November 28 2007 @ 9:56 pm

    grazie per avermi risposto sei molto gentile

  5. Klaus Herzberg said

    am January 31 2008 @ 5:27 pm

    Nice code. But do you know why it doesn’t work with the property “DoubleBuffered=true” ?

    If I enable DoubledBuffered threre is only a black border.

    Thanks. klaus.

Comment RSS · TrackBack URI

Leave a comment

Name:

eMail:

Website:

Comment: