954,518 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

System Running time

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.

Mongz
Light Poster
42 posts since Apr 2009
Reputation Points: 7
Solved Threads: 1
 

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

Ramy Mahrous
Postaholic
2,196 posts since Aug 2006
Reputation Points: 480
Solved Threads: 276
 

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

ddanbe
Senior Poster
3,829 posts since Oct 2008
Reputation Points: 2,070
Solved Threads: 661
 

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

Mongz
Light Poster
42 posts since Apr 2009
Reputation Points: 7
Solved Threads: 1
 

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
}
ddanbe
Senior Poster
3,829 posts since Oct 2008
Reputation Points: 2,070
Solved Threads: 661
 

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

  }
}
Attachments daniweb.timer_.zip (15.85KB)
sknake
Industrious Poster
4,954 posts since Feb 2009
Reputation Points: 1,764
Solved Threads: 735
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: