0

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.

4
Contributors
5
Replies
6
Views
8 Years
Discussion Span
Last Post by sknake
0

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

0

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 by ddanbe: n/a

0

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 by sknake: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.