Ticking time on a label
-
Am trying to make the label's text to the current time, but not using the 'static' DateTime.Now property which I tried to use lately. How can I go about it.Please help. :((
Use BackGroundWroker Process (i.e. a different thread) to update the time on label after every 1 sec(or whatever interval you like)
Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
-
Am trying to make the label's text to the current time, but not using the 'static' DateTime.Now property which I tried to use lately. How can I go about it.Please help. :((
You could use the Timer class, which is simpler than explicitly creating another process:
protected Timer tim = new Timer(); // Create timer.
...
// Set up timer:
tim.Tick += new EventHandler(tim_Tick); // Called at timer intervals.
tim.Interval = timerInterval; // Set timer interval....
private void tim_Tick(object sender, EventArgs e)
{
// Set label to current time...
} -
Am trying to make the label's text to the current time, but not using the 'static' DateTime.Now property which I tried to use lately. How can I go about it.Please help. :((
avoid using threads to update your gui , insted use events . also you can use DateTime.Now to get the time
Vikas Amin
My First Article on CP" Virtual Serial Port "[^]
modified on Thursday, July 24, 2008 5:33 PM
-
avoid using threads to update your gui , insted use events . also you can use DateTime.Now to get the time
Vikas Amin
My First Article on CP" Virtual Serial Port "[^]
modified on Thursday, July 24, 2008 5:33 PM
I have threads update my GUI all the time, but they have to be done properly. I don't see how an event would help avoid using a thread.