Saturday, July 25, 2009

How to create a Splash Screen in VB.NET 2008

VB.NET 2008 provides functionality to display a splash screen on application startup. Most people choose to use the generic splash screen for their applications, but those tend to make my life miserable when I go to edit them to what I want them to look like, so instead I will show how to take a regular Windows Form and turn it into a splash screen. In this tutorial, I'll show you how to:
  • Add a Windows form.
  • Change the form properties to be visually similar to a splash screen.
  • Add text and tables to the form
  • Make the application display the splash screen on start up.
  • Customise the splash screen display time.

Add A Windows Form

You can add a new form by going to Project>Add Windows Form, then add a new blank form and name it as SplashScreen.vb. The advantage of the generic splash screen is that all the form properties are already set and the form comes with a background, but as Ive seen and worked with these generic forms, they tend to not be as flexible as they should be, and you cant manipulate them as easily as a blank form can be manipulated.

Changing the Form Properties

Locate the properties for the form you have now created. Scroll down the properties box until you find the option for ControlBox. This by default is set to True. You will need to change it to False. Once you set the ControlBox to False, the form no longer looks like a typical form.

Ive also set the MaximizeBox and MinimizeBox both to false just in case, to lock the form from being user manipulated. I like to Lock the form, so that I dont accidentally manipulate the size of it, I usually use the form dimensions in the form properties box to manipulate the dimensions of the form precisely. This is an option, so feel free to do what comforts you as you design the form.

Finally before you start adding things to the form, you need to add a background. It can be a generic image you have on your computer, or it can be a company logo made to fit the size of the form. Any thing will work, just so that your form can be seen.

Adding Form Items to Customize the Form

Now that you have a properly formatted blank splash screen form, you still need to add text and tables to be able to fill in your Application Name and Copyright information, etc. In the toolbox, locate the TableLayoutPanel component, and add it to the form. Drag the corners of the table to manipulate it depending on the size you want, and you can add columns and rows to it also. You can also add text to identify your program, or a progress bar to show the program as it is loading the rest of the application.

Make the Application Display the Splash Screen on Start Up

From the Solution Explorer open My Project Properties, select the Application tab and then from the Splash screen: drop down select the Splash Screen you have added to your project (by default SplashScreen1) At this point you can run your project and a splash screen will be displayed for a minimum of 2 seconds before your main project form is displayed.

Customise the Splash Screen Display Time

Find the Timer Control in the Toolbox, and click on the form to add a new timer. Now go to the code and add the following lines of code in your Form_Load Sub Function:

Timer1.Enabled = True
Timer1.Interval = 800 '0.8 seconds

This will enable your timer, assuming you kept the default name, and it will add a timer that will last 800 milliseconds, or approximately 8/10 of a second.

If you've done all the steps correct, you should have a working splash screen, that you made from scratch! If you have any trouble, or need any assistance with this, feel free to leave a comment, and I'll get back to you when I can.

Be sure to read more of my tutorials.

2 comments:

  1. put this in to your code

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

    ReplyDelete
    Replies
    1. yes but in the 'application events' here is the link to the original code:
      http://www.sourcecodester.com/tutorials/net/how-create-a-splash-screen-vbnet.html

      Delete