Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using System.Diagnostics; //Stopwatch 클래스 이용 위함
- namespace stopwatch_2
- {
- public partial class stopwatch_2 : Form
- {
- public stopwatch_2()
- {
- InitializeComponent();
- }
- //스톱워치 클래스를 이용하여 인스턴스 생성
- Stopwatch stopWatch = new Stopwatch();
- private void myTimer_Tick(object sender, EventArgs e)
- {
- //흐른 시간은 지금 현재 시각 - 시작 시각
- TimeSpan flowTime = stopWatch.Elapsed;
- //흐른 시간 출력
- lblTime.Text = String.Format("{0:00}:{1:00}:{2:00}", flowTime.Hours, flowTime.Minutes, flowTime.Seconds);
- }
- private void btnStatus_Click(object sender, EventArgs e)
- {
- //시작 버튼일 경우, 중지 버튼으로 변경
- if (btnStatus.Text == "시작")
- {
- btnStatus.Text = "중지";
- //스톱워치 시작
- stopWatch.Start();
- }
- //중지 버튼일 경우, 시작 버튼으로 변경
- else
- {
- btnStatus.Text = "시작";
- stopWatch.Stop();
- }
- //타이머 활성화, 비활성화
- myTimer.Enabled = !myTimer.Enabled;
- }
- private void btnExit_Click(object sender, EventArgs e)
- {
- //나가기
- this.Close();
- }
- private void btnReset_Click(object sender, EventArgs e)
- {
- //중지한 상태에서 초기화 버튼을 눌렀을 경우
- if (btnStatus.Text == "시작")
- {
- stopWatch.Reset();
- lblTime.Text = "00:00:00";
- }
- //초를 재던 중 초기화 버튼을 눌렀을 경우
- else
- {
- stopWatch.Restart();
- btnStatus.Text = "중지";
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement