none
c# running time applications RRS feed

  • Pregunta

  • hi!! it's me again, does anyone know the easy way to make a running time application.
    I want to refresh automaticaly a label with the current time

    thank!!

    lunes, 18 de mayo de 2009 6:48

Respuestas

  • hi!! it's me again, does anyone know the easy way to make a running time application.
    I want to refresh automaticaly a label with the current time

    thank!!


    Drag a timer control and a label to the form.

    Set the timer interval to 1000 milliseconds (1 second) and start the timer. You can refresh the label using timer_tick event of the timer.

    If you're planning to use it in more than one form i would recommend inserting it in a UserControl.

    Here's the snippet:

    public Form1()
    {
        InitializeComponent();
        this.timer1.Interval = 1000;
        this.refreshTime();
        this.timer1.Start();
    }

    private void timer1_Tick(object sender, EventArgs e)
    {
        this.refreshTime();
    }

    private void refreshTime()
    {
        this.label1.Text = DateTime.Now.ToString("hh:mm:ss");
    }

    Hope it helps.


    Colabora con la comunidad, si éste mensaje te ha sido de utilidad, márcalo como respuesta correcta.
    lunes, 18 de mayo de 2009 7:10