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…

Letters, open and counters

In this Information age, the opinions of people are shaped by the discourse that happens in the media – the newspapers, the internet forums, the videos that are shot, the letters, open letters and counter letters. A vast majority of them are full of half-truths and that is not surprising as every side has skeletons to hide. The problem arises when a gullible population (read Indians) digest these printed words both offline and on as the ultimate Truth without question. Secondary sources and even imaginary accounts becomes Gospels to be used to shut anyone who dares to oppose the mainstream discourse.
The Quint has recently published an open letter by a veteran soldier of the Indian Army named Major Gaurav. They apparently waited for a counter to that which was furnished by a Wasim Khan, a ‘Kashmiri’ who now is settled in Mumbai and runs a successful media agency (not surprising). So before we go into braindead blaming attempts, let’s analyze the two pieces one by one and check the m…

The Man and the Qu'ran in Bangalore

I stayed for 3 years in Bangalore. There were places I loved in the city, places that I liked and a few places that I hated. There were also places about which I cannot make up any opinion at all.

Among them was the Jumma Masjid on the Dispensary road. This is not to be confused with the more famous Trust by the same name that is close by.

The area around is always busy and the commercial street is also close. The markets were always full of customers, shopkeepers sold exotic items. Just a few hundred meters and you could also visit the markets selling lots of stolen goods, though the shopkeepers often deny that and then wink to show that they were bluffing. It is a fun place for a man to be in, a bit scary for many women, except in a crowd.

Anyway, I always found the place inviting in a peculiar way, the nearby Salafi mosque preaching the evils of other religions, the stench of the urinals, the cheap stolen goods in the market, the prostitutes on the road, the hustle and bustle of t…