ITSourceCode.com

We Exist to Provide 100% Free Source Code and Tutorials

Custom Search

How to Create an Animated Text in VB.Net

In this tutorial, I will teach you how to animate a text in VB.Net. With this, it will animate just like fading the text in the Form.

 

So, let’s begin:

 
Open the Visual Studio 2008, create a new Windows Form Application. And drag a Timer on it.
anematedtextform_0
Go to the solution explorer and hit the code view.
anematedtextform2_0
In the code view, set up your imports above the Public Class.

  1. Imports System.Drawing.Drawing2D
  2. Imports System.Drawing.Text

After setting up the imports, declare the protected and constant variables that are needed.

  1. Const t_interval As Integer = 15 ' INTERVAL IN MILLISECONDS
  2. Protected cur_gradient_shift As Integer = 10
  3. Protected cur_gradiant_step As Integer = 5

Go back to the Form Design, and double click the timer. In the Timer_Tick method, you have to set the animated text.

  1. Private Sub Timer_Tick(ByVal obj As Object, ByVal ea As EventArgs) Handles Timer1.Tick
  2. 'SET THE GRAPHICS OBJECT IN THE FORM
  3. Dim grfx As Graphics = CreateGraphics()
  4.  
  5. 'SET THE SIZE,FONT AND TEXT.
  6. Dim fnt As New Font("Arial Rounded MT Bold", 25, _
  7. FontStyle.Regular, GraphicsUnit.Point)
  8. Dim start_text As String = "WWW.ITSOURCECODE.COM" 'IT WILL APPEAR ON THE FORM IN THE FIRST LOAD
  9. Dim fnt_size As New SizeF(grfx.MeasureString(start_text, fnt))
  10.  
  11. 'IT WILL CENTER THE TEXT IN THE CLIENT AREA.
  12. Dim ptf_text_start As New PointF( _
  13. CSng(ClientSize.Width - fnt_size.Width) / 2, _
  14. CSng(ClientSize.Height - fnt_size.Height) / 2)
  15.  
  16. 'FOR THE ANIMATION EFFECT, YOU HAVE TO SET THE GRADIENT START AND ITS END POINT.
  17. Dim ptf_gradient_start As New PointF(0, 0)
  18. Dim ptf_gradient_end As New PointF(cur_gradient_shift, 130)
  19.  
  20. 'YOU HAVE TO USE THE BRUSH TO DRAW THE TEXT.
  21. Dim gradient_brush As New LinearGradientBrush(ptf_gradient_start, _
  22. ptf_gradient_end, Color.Teal, BackColor)
  23.  
  24. 'SET THE TEXT TO DRAW AT THE CENTERED OF THE CLIENT AREA.
  25. grfx.DrawString(start_text, fnt, gradient_brush, ptf_text_start)
  26. grfx.Dispose()
  27.  
  28. 'IT WILL REVERSE THE GRADIENT WHEN IT GETS TO A CERTAIN VALUE.
  29. cur_gradient_shift += cur_gradiant_step
  30. If cur_gradient_shift = 500 Then
  31. cur_gradiant_step = -5
  32. ElseIf cur_gradient_shift = -50 Then
  33. cur_gradiant_step = 5
  34. End If
  35. End Sub

After setting up the animation, Go back to the design views and double click the Form. Then, start and set the interval of the Timer and to start the animation on the first load.

  1. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  2. 'START AND SET THE INTERVAL OF THE TIMER
  3. Timer1.Start()
  4. Timer1.Interval = t_interval
  5. End Sub
Facebook Comments

Check Your Domain Ranking

Leave a Reply

Your email address will not be published. Required fields are marked *

ITSourceCode.com © 2016 Frontier Theme

Subscribe For Latest Updates

Signup for our newsletter and get notified when we publish new articles for free!