Search - Articles
DevASP.NET for ASP.NET, VB.NET, XML and C# (C-Sharp) Developers Tuesday, March 03, 2009
Dev Articles
Search Directory
ASP.NET
VB.Net
C-Sharp
SQL Server
 

How we can Create Billboard with Lightening Effect Using VB.Net

Author: DevASP
Download Source Code : 530_TextAnimation.zip

In this article I Will Explain How we can Create Billboard with Lightening Effect Using VB.Net. Using Timer and some functionality. In many Applications we need to use Such Animated Things.

Creating the Create Billboard with Lightening Effect in VB.net seems to be critical but In fact theses types of things are not critical. For such type of application we have the easiest way to create them using Timer component given .Net Studio.

 

To create Animated application Follow Some Steps and Understand Code Below.

 

1. Create new application Using File menu and Choose vb.net project.

Now you will see the form Open in your application.

 

2. Now drag the timer component from Toolbox on your Form.

 

3. Now Double click on timer. That action will make An event of Timer.

 

4. Use the Properties window to set the individual properties of the Timer you created.

 

5. Now Initialize some Variables Before the Load Event Means Globally.

 

Const TEXT_TIMER_INTERVAL As Integer = 15 ' In milliseconds

Protected intCurrentGradientShift As Integer = 10

Protected intGradiantStep As Integer = 5

 

6. Now Double Click On Your Form. You Will See That in Code File the Auto Generated Function Appears; which is In fact Form’s Load Event. Now you can use that Function in your own way. Write these Lines of code in forms load event.

 

Private Sub SalmanText_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

 

        tmrAnimation.Interval = TEXT_TIMER_INTERVAL

        OnResize(EventArgs.Empty)

 

End Sub

 

7. Now write this Routine Which is the Autogenerated Event By Timer. This routine in fact Obtain the Graphics object exposed by the Form. The Functionality is written below:

 

   1- Set the font type, text, and determine its size.

   2- Set the point at which the text will be drawn: centered in the client area.

   3- Set the gradient start and end point, the latter being adjusted by a changing value to give the animation affect.

   4- Instantiate the brush used for drawing the text.

   5- Draw the text centered on the client area.

   6- Shift the gradient, reversing it when it gets to a certain value.   

 

    Private Sub tmrAnimation_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrAnimation.Tick

 

        Dim grfx As Graphics = CreateGraphics()

        Dim font As New Font("Microsoft Sans Serif", 96, _

            FontStyle.Bold, GraphicsUnit.Point)

        Dim strText As String = "Salman"

        Dim sizfText As New SizeF(grfx.MeasureString(strText, font))

        Dim ptfTextStart As New PointF( _

    CSng(ClientSize.Width - sizfText.Width) / 2, _

    CSng(ClientSize.Height - sizfText.Height) / 2)

        Dim ptfGradientStart As New PointF(0, 0)

        Dim ptfGradientEnd As New PointF(intCurrentGradientShift, 200)

        Dim grBrush As New LinearGradientBrush(ptfGradientStart, _

            ptfGradientEnd, Color.Red, BackColor)

        grfx.DrawString(strText, font, grBrush, ptfTextStart)

        grfx.Dispose()

        intCurrentGradientShift += intGradiantStep

        If intCurrentGradientShift = 500 Then

            intGradiantStep = -5

        ElseIf intCurrentGradientShift = -50 Then

            intGradiantStep = 5

        End If

    End Sub

 

 

8. Now Finally Make the last routine. Which actually Will Do the resize functionality. This method overrides the OnResize method in the base Control class. OnResize raises the Resize event, which occurs when the control (in this case, the Form) is resized. Obtain the Graphics object exposed by the Form and erase any drawings.

 

 Protected Overrides Sub OnResize(ByVal ea As EventArgs)

        Dim grfx As Graphics = CreateGraphics()

        grfx.Clear(BackColor)

End Sub

 

Now Built and run the Project Your You will see the Billboard with Lightening Effect. The source Code is given by this article for your Complete Understanding. Just run it you can understand how easily we can create animated Things in VB.Net. 

Article Comments
i hav taken it after using i will give u feedback

Posted on 3/30/2010 7:34:21 AM by Ashish

   
Add Article Comment:
Name :
Email Address :
   
Comments :
 
   
<< How we can Create Eye Wink Wall Paper in VB.Net.

Disclaimer - Privacy
© 2002-2017 DevASP.net