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.

Recommended Answers

All 5 Replies

Counter?? what about to see System.Time class?

What have you tried for yourself so far?
How would you start to tackle the problem?

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
}

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();
    }

  }
}
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.