Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C# (http://www.go4expert.com/forums/c-sharp/)
-   -   How to use timer control in C#? (http://www.go4expert.com/forums/timer-control-c-sharp-t4112/)

shah123 2May2007 14:01

How to use timer control in C#?
 
Hi,

How to use timer control in C#?

Any example please? Thanks

shabbir 2May2007 14:15

Re: How to use timer control in C#?
 
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.

shah123 2May2007 14:19

Re: How to use timer control in C#?
 
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();
            }
        }



All times are GMT +5.5. The time now is 22:22.