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

Operational Situational Summary - Ukraine 2 March

From a glance at the map and the news reports, it appears that the Russian advance has been very slow or even checked. However, a deeper look shows the situation has worsened significantly for Ukraine. That this happened as per my expectation in the past few posts makes me feel worse. In the North, the Russian forces have already encircled Chernihiv in the past couple of days. This is not yet fully updated on this map. The two strong armored spearheads from Konotop (which had also fallen) are currently holding in Pryluky and Nizhyn. The Chernihiv garrison probably has a day or two before the Russians reach Kozelets. Then any breakout attempt to Kyiv will become extremely difficult and will likely result in very heavy losses. It is to be expected that this city too, will fall soon without affecting the battle of Kyiv. This is bad for Ukraine. Now that the International Community has rallied for Ukraine, the previous fears of Russia dealing with breakaway republics in the East should be

Growing up

Time affects everything and everyone We all grow up. After college, friends go places, to different states and far away countries. You get less and less time. Some go for higher studies, again, in other states. Parents get older. Then friends start getting married. First it’s usually the girls. One by one, your crushes tie the knot. You dismiss it, you are still young. Then your guy friends start getting married too. Your circle shrinks. In the end you look around. All you are left with are ideological nutjobs, immature imbeciles, idealistic crazies, bohemian hippies, or other misfits. Do you really belong here? Okay, that was too harsh. But you think. You say to yourself, ‘ dil to baccha hai jee ’.  Okay, fair enough. And then... Then, you see a growing pot belly. Something you always despised. Your dad had one (he still does). After taking a shower, you look at the mirror. You are losing hair. You search on Amazon for hair growing products - it is too much of a hassle. Hair transplan

Operation Situation Report Summary - Ukraine 4 March

 Defense Without Strategy Ukraine seems to be hell bent on fighting a static war without almost any flexibility. Their forces may be valiant and defiant, but without a coherent strategy, the best they can hope for is to prolong their own suffering WITHOUT significantly hurting the enemy. Here is how the situation stands as of now. Kherson has fallen. The front in the South was decisively broken day before yesterday with the capture of the railway station and port. Naturally, the Russian forces did not wait and moved straight North to Mykolaiv. All UA forces on the Dnepr facing South are likely to be outflanked. Unless the Russian spearheads are cut off and destroyed in a day or two, it will be too late. The fall of the entire South seems to be inevitable.  To extricate the forces, UA should have withdrawn forces from other sectors (including far away Donetsk front). Now, the best they can try is to win time to reinforce Kyiv. Kharkov is almost surrounded. This battle seems to be fought