Tip!
I got a tip for you all. If you want to display a current time realtime, create a timer object and assign an interval to be 1000 and set the Enabled property to true. Declare a DateTime variable and put in the code inside the timer event. Assign a DateTime variable to the label control once you convert to string by calling like:
labelName.Text = DT.ToString();
Where labelName is assigned to a label control and DT is a DateTime Variable.
To give you a better explaination, create a Visual C# project called WFormClock. (W stands for Windows.) Note that I have Visual C# .net.
In Solutions Explorer, right click WFormClock, go to Add, and click Add User Control. There, type Clock and click Okay. This creates a user control designer, where you can have 2+ controls inside one user control (for example, a label and a timer object).
In the Windows Form Toolbox, grab the two items: the label, and the Timer.
Rename 2 controls:
label1 = lblClock
timer1 = tClock
Dock the lblClock's control to the center and set the TextAlign property to Middle.
In the tClock's property, set the Interval to 1000 and enabled property to true. Double-click the tClock component and declare the DateTime Control at the top of the tClock event.
In the tClock event, write the code:
Code:
// C#
private void tClock_Tick(object sender, System.EventArgs e)
{
DateTime DT = DateTime.Now;
lblClock.Text = DT.ToString();
}
Compile the control and bring the Clock control to the Windows Form application. Clock can be found under the Windows Form Toolbox. When you do add the clock control to the project, notice the control right away!
What it does is the control shows you the clock real-time!
Compile Widnows Form (WFormClock) and Start Without Debug.
Pretty simple! It's very easy to do, and very easy to code!