Full width home advertisement

How To

Science

Post Page Advertisement [Top]


This is a simple tutorial on how to create a simple clock application using c# programming language. This tutorial has been redefined to make it more simpler for beginners to create. Follow the steps below

1. Open Visual Studio

2. Create a new project - click on New project -> Windows Form Project and the name it Clock



3. Then you will see a blank form which is the design form.



4. Then add a label by clicking on it in Toolbox then drag it onto the design form.



5. Also add Timer - just click on the timer on the Toolbox and click on the form



6. Now click on the label, then navigate to the down-right side of the screen which is the properties pane or press F4 to get you there faster. Then you can format the appearance of the label.



7. Now double click on the timer1 located at the downward side, then it will take you to the code form.





8. Then paste the below code between the { } sign under "private void timer1_TickTick(object sender, EventArgs e)" heading.

//to display the time in the label
label1.Text = DateTime.Now.ToString("hh:mm:ss tt")

9. Then paste the below code between the { } sign under "private void Form1_Load(object sender, EventArgs e)" heading.

this.Text = "Digital Clock";
//To set the title
timer1.Start();
//starting the timer


Below is the complete code for the application

using System;
using System.Windows.Forms;
namespace Clock
{ 
public partial class Form1 : Form 
{ 
public Form1() 
{ 
InitializeComponent(); 
} 
private void Form1_Load(object sender, EventArgs e) 
{ 
this.Text = "Clock"; 
//To set the title 
timer1.Start(); 
//starting the timer 
}
private void timer1_Tick(object sender, EventArgs e)
{ 
//to display the time in the label 
label1.Text = DateTime.Now.ToString("hh:mm:ss tt"); 
} 
} 
}


The below screenshot is the result of the application.



No comments:

Post a Comment

Bottom Ad [Post Page]

| Designed by Colorlib