First, you drag a Timer control over to the form you are using (or double-click it). This will put it in the tray at the bottom.
Next, choose some event in which you want to start the timer. Put the following code:
Timer1.Start()
(The code will be the same in C# as it is in VB.Net, but you will need to add a semi-colon at the end of the statement)
For the Interval (using the Property Window), enter an interval you are comfortable with. The interval is measured in miliseconds, so if you want it to be 3 seconds, enter 3000.
Next, click on the timer control, to select it, and in the Property Window, click the ‘Events’ icon. Double-click the ‘Tick’ Event. Now, you will be in the code window, with a new event for the Tick Event. Here is where you enter your code for what you need to be accomplished.
Simple Scenario:
A form opens – a button is in the middle of the form and is disabled, but in 3 seconds, it should be made enabled.
Create a form, put a button in it, and set the button’s Enabled property to ‘False’. Drag a Timer to the form, and set the interval to 3000. In the form’s load event put:
Timer1.Start()
In the Timer1’s click event, put:
Button1.Enabled = True
When you run the application, when the form opens, the button is disabled. Then, after three seconds, the button becomes enabled.
And that’s how you use the Timer control in a Windows Forms application.
All Things DotNet Discussed – Winforms/ASP.Net/SharePoint/WPF
Leave a reply
You must be logged in to post a comment.