Tuesday, December 9, 2014

How to make a digital clock in C#

It is very easy to make a digital clock in C#. Just a three lines of code can make a wonderful digital clock. Lets Start...

1. Create a new project and name it anything you want like DigitalClock.


2. Add two labels from the left tool panel.


3. Now the code to show date and time in the label is very simple. In the below figure label1 has the code to show time and label2 has the code to show date.


4. But if you execute this program then it will show like a clock but it will not work like the real clock. So to make it run like a real clock you have to use timer.
>> Add a timer to the form by double click on the timer which on the left toolbox.

5. Now double click on the timer1 and the code which we have written in form load, move the code to timer1 by Ctrl+X / Ctrl+V. And in the form load write the code >> timer1.enable = true;

Now if you execute the program it will work perfectly. Now you should design it better and make the clock more awesome. You can use the .exe file of this digital clock anytime. For .exe file for this
1. Go to the folder where you have saved this project. Example "C:\Users\Pirates\Documents\Visual Studio 2008\Projects\DigitalClock"
2. Go inside the folder DigitalClock >> now inside the folder bin >> now inside the folder debug
3. Now there is the .exe file. You can use this clock in the windows anytime now.

Make the design good. Here is an example of the final result.

0 comments:

Post a Comment

Share

Twitter Delicious Facebook Digg Stumbleupon Favorites More