Hello World

C#(WINFORM, WINCE, WINDOWS MOBILE) 실전 활용 예제소스 및 프로그램 개발

[C#]카운트다운 예제

댓글 1

C#

2018. 5. 16.

double nTotalSeconds = 90;

DateTime dt;

private void Form_Load(object sender, EventArgs e)
{
 dt = new DateTime();
 
 timer1.Interval = 1000;
 
 timer1.Enabled = true;
}

private void timer1_Tick(object sender, EventArgs e)
{
 nTotalSeconds--;
 
 textBox1.Text = dt.AddSeconds(nTotalSeconds).ToString("HH:mm:ss");
 
 if(nTotalSeconds == 0)
  timer1.Enabled = false;
}


출력
00:01:30
00:01:29
00:01:28
.
.
.
00:00:00