Hi guys, im not well experienxed please help, i want to code a digital running time with the colon dots flickering to show that the time is running anyone can offer help will be very usefull.

I'v tried to get using

System.DateTime.Now

but this is not a running time, then the

System.Timer

gives me errors. Any help

Start with using something like this:

// init a Timer class
Timer aClock = new Timer();
// install an event
aClock.Tick += new EventHandler(WhenTheClockTicks);
// let it tick every second
aClock.Interval = 1000;
// start the clock
aClock.Start();

private void WhenTheClockTicks(object sender, EventArgs ea)
{
// You will get here every second, so do what you have to do
}

Edited 7 Years Ago by ddanbe: n/a

Try this out

Here is the meat of what you're requesting (I think):

using System;
using System.Windows.Forms;
using Timer = System.Timers.Timer;

namespace daniweb.timer
{
  public partial class frmSystemTime : Form
  {
    private Timer timer;

    public frmSystemTime()
    {
      InitializeComponent();
      timer = new Timer();
      timer.Interval = (1000 * 1); //1 sec
      timer.AutoReset = true;
      timer.Elapsed += new System.Timers.ElapsedEventHandler(timer_Elapsed);
    }

    private void frmSystemTime_Load(object sender, EventArgs e)
    {
      UpdateLabel();
      timer.Enabled = true;
    }

    private void UpdateLabel()
    {
      if (label1.InvokeRequired)
      {
        label1.Invoke(new MethodInvoker(UpdateLabel));
      }
      else
      {
        label1.Text = DateTime.Now.ToString("G");
      }
    }

    void timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
    {
      UpdateLabel();
    }

  }
}

Edited 7 Years Ago by sknake: n/a

This article has been dead for over six months. Start a new discussion instead.