Tuesday, November 18, 2014

Program The Timer Control In Vb Internet

In Visual Basic .NET, the Timer control lets you control recurring events during run time for your application. Timer has few properties and methods that are unique to it. Its most important property is Interval, which specifies how often the Timer should execute its code. You supply an Interval value in milliseconds; 1,000 milliseconds equals one second. Some examples of what you can do with a Timer control include performing a countdown, dynamically changing property values for other controls and maintaining a constant watch on some other part of the application.


Instructions 0 Then


time = time - 1


Label1.Text = time


Else


Timer1.Enabled = False


End If


When the program runs, the Timer will decrement the time variable by one every second, and display the value on the label, until the count reaches 0, at which point the Timer turns off.


4. Press "Shift" and "F7" to open the design window. Double-click the Timer control to add Timer2 to the project. Change its Enabled property to True and its Interval property to 100, then double-click it to open the Timer2_Tick subroutine. Type the following code:


If (Label1.Left + Label1.Width) > Me.Width Then


Label1.Left = Me.Left - 100


End If


Label1.Left = Label1.Left + 5


This code causes the label to scroll horizontally across the screen, moving five pixels every tenth of a second. When the label reaches the right end of the form it jumps back to the left and begins scrolling across again.


5. Press "Shift" and "F7" to open the design window. Double-click the Timer control to add Timer3 to the project. Change its Enabled property to True and the Interval property to 500. Double-click the TextBox control to add TextBox1 to the project. Double-click Timer3 on the project to open the Timer3_Tick subroutine. Type the following code:


TextBox1.Text = TextBox1.Text.ToUpper


TextBox1.Select(TextBox1.TextLength, 0)


Every half-second the Timer changes all the text in TextBox1 to uppercase. By default, when the Timer makes this change it moves the cursor back to the beginning of the text box. The second line of code prevents this from happening.