Professional Documents
Culture Documents
Timer
LAB 11
Muhammad kamran
Email: kamran_comsian@ymail.com
Timer Control
• Windows Forms have a Timer control that can be
used at design time as well as at run-time.
2
Timer Class Properties
• t.Interval = 2000;
• timer1.Enabled = true;
3
Creating a Timer
• A Timer control does not have a visual representation
and works as a component in the background.
• Design-time
• You can create a timer at design-time by dragging and
dropping a Timer component from Toolbox to a Form.
• After that, you can use F4 or right click Properties
menu to set a Timer properties as shown in Figure 1.
• As you can see in Figure 1, the Enabled property is
false and Interval is set to 1000 milliseconds (1
second).
4
Creating a Timer
5
Figure 1
Creating a Timer
• First thing you want to do is, change Enabled
to true so the timer will start when your
application starts.
7
Creating a Timer
• {
• }
8
Creating a Timer
• Now whatever code you write on this event handler, it will be
executed every 1 second.
• For example, if you have a ListBox control on a Form and you want to
add some items to it, the following code will do so.
• {
• listBox1.Items.Add(DateTime.Now.ToLongTimeString() + "," +
DateTime.Now.ToLongDateString());
• }
• 9
10
Questions?