Click here to Skip to main content
15,890,609 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
Well, as a start, this is my first post.
I have little to no c# experience but, I have had a lot of PHP at school about a month ago, also, HTML is a peace of cake for me.

So, now my question.

I want to make a real time clock for my WindowsForms application and I want it to make it out of a label. So, how do I do that?

I'm using:
C#
label1.Text = DateTime.Now.ToString("HH:mm:ss");

but, it won't refresh.

sorry, for me, being so dumb....
Posted
Updated 27-Mar-11 0:30am
v3

It won't refresh if you don't refresh it. Use a timer and write the same very code line you posted in the timer event.

C#
Timer timer = new Timer();
timer.Interval = 500;
timer.Tick += (sender, eventArgs) => {
    myLabel.Text = System.DateTime.Now.ToString("MM:hh:ss");
}; 
timer.Start();


—SA
 
Share this answer
 
v2
Comments
Just_Michel 26-Mar-11 17:36pm    
how? :$
example?
Sergey Alexandrovich Kryukov 26-Mar-11 17:48pm    
Try yourself first, ask a follow-up Question if you face any problem. This is how CodeProject usually work. This is easy to do, a matter of minutes.
Please post it using "Improve question".
--SA
Richard MacCutchan 27-Mar-11 6:58am    
Neat solution, have a 5.
Sergey Alexandrovich Kryukov 27-Mar-11 14:13pm    
Thank you, Richard, that's easy.
--SA
CPallini 27-Mar-11 8:20am    
5.
public The_Launch()
{
InitializeComponent();
System.Windows.Forms.Timer timer = new System.Windows.Forms.Timer();
timer.Interval = 500;
timer.Tick += (sender, eventArgs) =>
{
label1.Text = DateTime.Now.ToString("HH:mm:ss");
};
timer.Start();
}


and, it works..
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900