animated text using vb.net

0

Category:

   Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
      
        'I have used Button1 as a reference as to where I want the label to appear
        animateText("You have gained 5 points", Button1.Location.Y - 20, Button1.Location.Y - 50, Button1.Location.X)
    End Sub

    Dim blah As New Label 'Makes a new label
    Dim maxHeight As Integer
    Dim colour As Integer = 255 'This will be used for fading the text from white to black

    Public Sub animateText(ByVal text As String, ByVal lowerBounds As Integer, ByVal upperBounds As Integer, ByVal xPos As Integer)

        'lowerbounds = where the label gets created
        'upperbounds = where the label dissapears

        maxHeight = upperBounds 'The variable maxHeight is used in the timer event to tell it where to dissapear, so I populate it using the sub

        blah.Text = text
        blah.TextAlign = ContentAlignment.MiddleCenter
        blah.Location = New Point(xPos, lowerBounds)
        blah.Font = New Font(Font.Bold, 20) 'Feel free to customize the font size
        blah.AutoSize = True

        Me.Controls.Add(blah)

        Timer1.Enabled = True

    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick

        blah.Location = New Point(blah.Location.X, blah.Location.Y - 1)
        blah.ForeColor = Color.FromArgb(colour, colour, colour) 'The variable colour starts out with 255(means label is White) and then slowly decreases to 0(means label is Black)
        colour -= 7 'I didn't have time, but I'm sure there is a MUCH more suitable value for this variable

        If colour <= 10 Then 'This is just used to prevent 'colour' being less than 0
            colour = 10
        End If


        If blah.Location.Y = maxHeight Then 'Makes the label dissapear
            Timer1.Enabled = False
            Me.Controls.Remove(blah)
            colour = 255
        End If

    End Sub

Comments (0)

Post a Comment

Copyright © 2009 virtualinfocom All rights reserved. Theme by Games. | animation Ani2Pix.