heyz... i need help. i new to C#. i need to add timer to my code. but i don't know how to do it... can help mi!! all i have done to the code is declared int time. :(:(

use timer from Toolbox ..

it is under Toolbox -> Components -> Timer

oh no.... this is not what i wanted... i jus want to show the time and date in my GUI. how to do that??

Here is an example of how to use a timer. Important to know: Timer tick is the method which is called when the timer come to zero:

public partial class Form1 : Form
    {
        Timer timer1;
        int counter;

        public Form1()
        {
            InitializeComponent();
            label1.Text = "countier: 0";
            CreatingTimer();
        }

        private void CreatingTimer()
        {
            timer1 = new Timer();
            timer1.Tick += new EventHandler(timer1_Tick);
            timer1.Interval = 1000;
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            counter++;
            timer1.Enabled = true;
            label1.Text = "counter: " + counter.ToString();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            timer1.Start();
        }
    }

Welcome Baby G

Drop a Label onto the Form and write following code in Form Load event

private void Form1_Load(object sender, EventArgs e)
        {
            Timer timer = new Timer();
            timer.Interval = 1000; //1sec
            timer.Tick+=(sa,ea)=>
                {
                    label1.Text = DateTime.Now.ToString();
                };
            timer.Start();
        }

does this codes work for visual studios ?? i tried but the output is still the same... as in no change at all!!

does this codes work for visual studios ??

Yes.

i tried but the output is still the same... as in no change at all!!

Hey, come on! ;) Please show us your code work.

Suggest you read a good book about VS and C#.

hehe....sorry i made a mistake... actually i can work ^^ thank you!!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.