How to use timer control in C#?

shah123's Avatar
Contributor
Hi,

How to use timer control in C#?

Any example please? Thanks
0
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
1. Have the timer control in your application or have a variable of type Timer.
2. Assign a event to the Timer tick event.
3. Enable the timer and start when you think you need the event.
4. After sufficient time elapse your function will be called.
0
shah123's Avatar
Contributor
I managed before you said above but thanks Shabbir. I did above now how to show current system time on the form at some specific position. Following is some sample of code I have
Code:
public Form1()
        {
            InitializeComponent();

            // Instantiate the timer
            timer1 = new Timer();

            // Setup timer
            timer1.Interval = 1000; //1000ms = 1sec
            timer1.Tick += new EventHandler(timer1_Tick);
            timer1.Start();
          
        }
Code:
 private void timer1_Tick(object sender, EventArgs e)
        {
            if (sender == timer1)
            {
                DateTime.Now.ToLongDateString();
            }
        }