Skip to main content

Make a Splash!

 

I was sitting at home, when suddenly I got a request to write a splash form. So I wrote this. It  is fairly simple to implement.

Just add a Windows Form to a new Visual Basic Project.

Add a Timer Control to the Form, named ‘theTimer’

Now add two labels, one for a statement, other to show the countdown. I have named them lbl1 and tmrLabel.

Go to its code of the Form and copy and paste this down. I have assumed the form name to be ‘MainFrm’. Run it and you are good to go. All with a fade in and fade out animation. Simple yet efficient. And to the friend who requested, it was a pleasure. :)

'''<summary>
''' A simple Splash Screen with basic fade in and fade out animation
''' A Program by Sarthak Ganguly
''' </summary>
''' Released under GPLv3 License
Public Class MainFrm

   'Declaring an Enum with form status
    Enum formStatus
        formOpening
        formShowing
        formClosing
    End Enum


    Dim _formStatus As formStatus = formStatus.formOpening
  
'You can select the animation speed here( fade in and fade out)
    Dim animationSpeed As Double = 0.1
 
  'stayOn is a counter variable
    Dim stayOn As Integer = 0
  
'limit is the time duration for which the form is to remain open
    'Here limit is 30 seconds
    Dim limit As Integer = 300

    'The form closing Event is essential to close the form when the
    'fades out completely, that is when the opacity reaches 0
    Private Sub MainFrm_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing

        If Me.Opacity = 0 Then
            theTimer.Dispose()
            Me.Dispose()
        End If

    End Sub

    'The Fade in Animation begins
    Private Sub MainFrm_Load(ByVal sender As Object, _
                             ByVal e As EventArgs) Handles Me.Load
        theTimer.Start()
        _formStatus = formStatus.formOpening

    End Sub

    'The Timer operations are done here
    Private Sub theTimer_Tick(ByVal sender As System.Object, _
                              ByVal e As System.EventArgs) Handles theTimer.Tick

        Try
            If _formStatus = formStatus.formOpening And Me.Opacity < 1 Then
                Me.Opacity += animationSpeed
                If Me.Opacity = 1 Then
                    theTimer.Enabled = False
                    Call ShowForm()
                End If
            ElseIf _formStatus = formStatus.formClosing And Me.Opacity > 0 Then
                Me.Opacity -= animationSpeed
                If Me.Opacity = 0 Then
                    theTimer.Dispose()
                    Me.Dispose()
                End If
            ElseIf _formStatus = formStatus.formShowing Then
                If stayOn < limit Then
                    stayOn += 1
                    tmrLabel.Text = CInt((limit - stayOn) / 10)
                Else
                    theTimer.Enabled = False
                    Call Form_close()
                End If
            Else
                theTimer.Enabled = False
            End If
        Catch ex As Exception
           
'There should not be any error, but still if there is
            'you'll know
            Console.WriteLine(ex.Message)
        End Try

    End Sub

    'Sends the formClosing status to the Timer
    Private Sub Form_close()
        _formStatus = formStatus.formClosing
        theTimer.Start()
    End Sub

    'Allows the timer to show the form for the duration
    'required
    Private Sub ShowForm()

        _formStatus = formStatus.formShowing
        theTimer.Enabled = True
        theTimer.Start()

    End Sub

End Class

You can get the compiled file from here

http://www.wikifortio.com/472019/SplashScreen.zip

I will also post it on sourceforge.net

Popular posts from this blog

Burhan Wani – The man and his mission

Burhan Wani – The man and his mission The death of a young ‘hero’? On the 8th of July, Burhan Muzaffar Wani died in the Valley of Kashmir. Thousands poured out on the streets to commemorate his services to the movement that he had come to symbolize of late. The relative calm of the region was shattered with curfews, killings and allegations of human rights abuses. His father was proud for the services his son had offered in the name of their faith, convinced that he would go to Heaven. Amidst all this, the romantic ideals of a young boy, just off his teens began to shake up the youth of the entire country, both in and beyond India. There is a lot of unrest in the Kashmir Valley recently, especially in the aftermath of the death, nay execution of Burhan. All of this is not unexpected in any way. In fact, this was foreseen. Even his glorification, his elevation to the status of a martyr in the service of Islam does not come as a surprise to me.
There is a section of the media and a sig…

The postman, Megha and I

This is a story that goes way back to 2001 or 2002. I was in the sixth standard. Yes, I do remember it quite vividly. It was funny, painful and a bit out of the ordinary – basically it had all the ingredients that allows a memory to stick a great while longer than others. In the process of my recollection, I may miss out a few pieces here and there, but it will be pretty accurate. Of course, the intention of this exercise is in no way to humiliate anyone else or point out the flaws about others’ actions. I now find it hilarious and I think so would you.
I studied in the Vivekananda Mission School, a private English medium school in Joka, on the outskirts of Kolkata. If you know the location of the Indian Institute of Management, Kolkata, you know the location of my school. I studied there till the twelfth standard. We had many students in our class (sixth). We were divided into several sections, ranging from A to F (not sure if it was F or G). But anyway, I was in section B, the sect…

Indian Partition - The Forgotten Question

The Partition of India was a terrible catastrophe. There is no doubt about that. Millions were killed, displaced, thousands were raped, orphaned etc. All this was done in a space of a few months. Mobs frantically killed each other for life, religion, property, identity, revenge and any other reason they could then think of. Even since the call for Direct Action, there was no doubt about a serious religious conflict. What followed was an eventual ethnic cleansing of parts of India of non Muslims and Muslims. How it happened, what happened, how trains full of dead bodies piled up on each side of new borders is well known. Hundreds of books have been written, research over decades have been published. We know all that.

The basic idea of it all was simple - Jinnah believed Hindus and Muslims are two separate nations and the latter should have a distinct political entity for themselves, based on Islam, their faith. To identify this they had to prove one thing. That the All India Muslim Le…