02/09/2011

How to create a moving text in VB.Net

To code a moving text in VB.Net.I have used timers and label control. the steps are as under:
1. Take two timers , name it Timer1 and timer2 and set its property.
          (a) Enable- True
          (b) Interval- 100





2. Take a label control and set the name property as label1 and text property what ever text you want to display and also set the font and fore color property as you desire.


3. Then write down following VB.Net code on timer.tick event:
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        Label1.Left = Label1.Left - 2 '
        If Label1.Left <= -527 Then ' Drag your level text on the form till it vanished from form and see the left position 
            Timer1.Enabled = False
            Timer2.Enabled = True
        End If
    End Sub

    Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
        Label1.Left = 1117            '  extreme left of your form
        Label1.Left = Label1.Left + 2
        If Label1.Left >= -385 Then
            Timer1.Enabled = True
            Timer2.Enabled = False
        End If
    End Sub


Label left position can be set as per the size of your form and length of text which you want to display. Happy coding.
For better understanding  of vb.net code or database related inquiry the book written by Mike Murach is very good book which is available on amazon with free shipping charge, I will suggest one can  refer.





No comments:

Post a Comment

What & How