Click to See Complete Forum and Search --> : Display Current Time - Auto Update


motorizedmedia
February 22nd, 2008, 11:45 PM
In one of my forms I have a label that is set to display the current time (as of when the form was loaded using the following script:



private: System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e) {

DateTime dt=System::DateTime::Now;

label2->Text= dt.ToString();

}



This is pretty much a time stamp, but what i want the label to do is to display the current time as if it were a clock so that it would automatically update itself. How would I go about accomplishing this?
Thanks,
JB

ovidiucucu
February 23rd, 2008, 02:39 AM
[ Redirected thread ]

darwen
February 23rd, 2008, 05:12 AM
Create a System::Windows::Forms::Timer member variable on your form and handle its tick event. I'd recommend a 500ms tick frequency.

Update the label's text on each tick event (if the time has changed - the easiest way of doing this is to compare the text in the label with the text for the new time).

You can start the timer in the form's Form1_Load method you already have.

Darwen.