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

Comments

Popular posts from this blog

My love affair with ThinkPads

I had never used a ThinkPad in my life till 2018. To be honest, I did not really see the benefit of using them anyway. Consumer series laptops (with plastic bodies) were the ones that I had always used before. Then I was introduced to the rugged looks of the T60 and T61 original IBM ThinkPad designs that came out way back in 2004 or so. And I loved it. Finding a ThinkPad that old did not appeal to me. I was impressed with the smaller compact X series laptops and decided to have either an X230 or an X220. Both of these are fairly similar and were launched about 8 years back. But they still sport good processors, plenty of memory upgradability, provision to add a maximum of three hard disks and a decent battery backup to boot. My reasons to get this were simpler -  They are rugged, I like to use my laptops well Memory is not soldered. There are plenty of options to upgrade. The keyboards are probably the best in the world. Why not get the latest ThinkPad? Again, simple.  They come with a

How To: Change Fonts On The 5800, 5233 etc

The font that comes with Nokia is nice. But after six months you are bound to crave for a new look to your phone. Now changing fonts on a phone is usually not an easy task, I mean that was how you must have thought. But you know what you can use custom fonts, yes any font of your choice on your Nokia phone without any software. All you need to do is copy and paste a bunch of files. No replacing of system resources necessary! First to increase your greed, I will post some screenshots, Screenshot Gallery o   Font Style Download o Another Font Style Now let me tell you how I did it. Procedure to apply new Fonts Connect the phone in the ‘Mass Storage’ profile to the computer. Alternatively, you can use the memory card reader. Goto the Memory Card, it shows up as a Removable Disk. Navigate to the ‘resource’ folder and open it. Copy the ‘Fonts’ folder into in. Eject the device and restart. You should see the new fonts applied. Procedure to apply your Fonts Ma

Reaching the peaks of my own stupidity or not

 I have never considered myself to be particularly intelligent. Though I have not had myself clinically diagnosed, anecdotal evidence and day to day activities amply demonstrate how stupid I am. Now wait. This does not mean I am indulging in self pity.  No. Far from it. I have had successes in life. I continue to do well in things that I love to do. I have no complaints there. It is just that I do feel my intelligence lacking. My success is, therefore, despite my stupidity and I take some pride in it. Of course defending the statement - 'I am stupid' is difficult. Especially without a test that ascertains the fact for certain. I will make a more nuanced statement as a result. I have less intelligence than the average person around me. That is a more defensible stance and there are tests (even other than IQ) to confirm it. Aptitude tests are a good example. I do horrible in them.  Okay, there is an exception - I got into IITB. But that was me trying for a third time. In any case