C#
[ C# ] Digital Clock
saltdoll
2015. 11. 3. 02:08
반응형
C#을 이용한 기본적인 디지털 Clock 소스입니다.
Steps
1. Visual Studio 실행
2. New Porject -> Windows Form Project 선택하고, 이름 입력 (ex: Digitalclock)
3. Toolbox에 있는 Label과 Timer을 from에 추가한다.
4. timer1을 더블 클릭합니다.
5. timer1의 timer_Tick소스안에
label1.Text = DateTime.Now.ToString("hh:mm:ss tt");을 입력합니다.
Form1.cs
using System;
using System.Windows.Forms;
namespace Digitalclock
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
this.Text = "Digital 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");
}
}
using System.Windows.Forms;
namespace Digitalclock
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
this.Text = "Digital 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");
}
}
}
6. 실행 화면
반응형