C# Programming: Time Display

Wednesday, October 3, 2012

Time Display

Welcome to my very first blog on programming on C#.Net. Today we are going to create a Time Display in c#.
Requrements: Visual studio installed.
steps:
1.Goto File >> New Project >> Select Language (C#) >>Select Template: Windows Form Application.
(This steps will not be in other projects ok guys :)
2.As default a form will appear.

 
Now change the properties of form1 as follows:
 (Right click on form1 and select properties)
  i) Text: Yuvi Timer
  ii) FormBorderStyle: None
  iii)ShowInTaskBar : False
 iv)StartPosition: Manual
 v) Size:403,97
 vi)Location: 875,700 (add according to your resolution)
 vii)BackgroundImage: (Add a image of size  about 403,97)

3.Now add  two components labe1 and a linklabel1 from the toolbox which usually is at left of the IDE(Visual studio). Change the text properties of label1 and linklabel1 as 'welcome' and 'Exit' as shown in picture below.
 Now your form should look like this:

4.Now add another component or object called Timer1 from the toolbox.Add the following properties to timer1:
 i)Enabled=True
ii)Interval=1000   (Here 1000 for 1 sec..ie 500 for 0.5 secs)
5.Now its time for coding :)
 Double Click on form11 and add the following code in form1 class as shown in picture below:
                DateTime current_time= new DateTime() ;    
  
   Double Click on timer11 and add the following code in timer1_tick function as shown in picture below:                   
                    current_time = DateTime.Now;    //to store current time in variable current_time
                    label1.Text = current_time.ToString();          

 //to display the time in label1 ..here text is property of label1 and ToString() is a function of object   //current_time to convert the object to string type.
  Now doubleclick on linklabel1 and inside linklabel1_click function add following code to exit the application:
    Application.Exit();
Now press F5 or press start debugging (green play) buttton to run the application.Now your time display application is ready.To get the exe file goto project folder>>bin>>debug>> and get your_app_name.exe file .Ok Enjoy guys, see you in next post :)
  

       



No comments:

Post a Comment