Timer Control for Visual Basic 6.0 Users
The Timer control in Visual Basic 6.0 is replaced by thecomponent in Visual Basic 2005. The names of some properties and events are different, and in some cases there are differences in behavior.
The Visual Basic 6.0 Timer control is an actual control that is sited on a form at design time; however it is not visible at run time.
The Visual Basic 2005 Timer is a component that is added to the tray at design time; as a component it has no Parent property.
In addition to the Timer component, the .NET Framework also has two timer classes:and .
In Visual Basic 6.0, you can disable a Timer control by setting the Interval property to 0.
In Visual Basic 2005, the lower range for theproperty is 1. If you set the interval to 0, it throws a run-time exception. The Visual Basic 2005 Timer component uses the property to allow you to disable or enable it.
Code Changes for the Timer Control
The following examples illustrate differences in coding techniques between Visual Basic 6.0 and Visual Basic 2005.
Code Changes for Starting and Stopping a Timer Control
The following code demonstrates how to enable and disable a Timer control at run time.
' Visual Basic 6.0 Public Function TimerOn(Interval As Integer) If Interval > 0 Then ' Start the timer. Timer1.Interval = Interval Else ' Stop the timer. Timer1.Interval = 0 End If End Function
Timer Control Property and Event Equivalencies
The following table lists Visual Basic 6.0 properties and events, along with their Visual Basic 2005 equivalents. Those properties and events that have the same name and behavior are not listed.
This table provides links to topics explaining behavior differences. Where there is no direct equivalent in Visual Basic 2005, links are provided to topics that present alternatives.
Properties and Events
|Visual Basic 6.0||Visual Basic 2005 Equivalent|
New implementation. For more information, see
New implementation. The Timer is a component and cannot have a parent.
When a Visual Basic 6.0 application is upgraded to Visual Basic 2005, any Timer controls are upgraded to Windows Forms Timer components. If code is found that sets the Interval property to 0, an upgrade warning is added to your code.