개발 노트

C# 스톱워치 본문

프로그래밍/C#

C# 스톱워치

알 수 없는 사용자 2022. 1. 18. 15:54

https://github.com/zakigaebal/stopwatchCS

 

GitHub - zakigaebal/stopwatchCS

Contribute to zakigaebal/stopwatchCS development by creating an account on GitHub.

github.com

 

 

 

더보기

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;

namespace WindowsFormsApp1
{
    public partial class Form1 : Form

    {
        //시, 분, 초 변수 선언
        public int minutes = 0;
        public int chos = 0;
        public int seconds = 0;
        public Form1()
        {
            InitializeComponent();
            //Start, Stop, Reset 버튼 클릭 이벤트 선언
            Btn_Start.Click += Btn_Start_Click;
            Btn_Reset.Click += Btn_Reset_Click;
        }
        private void IncreaseSecond()
        {
            //초가 99초 초과면
            if (seconds > 99)
            {
                seconds = 0;
                IncreaseCho();
            }
            else
            {
                seconds++;
            }
        }
        private void IncreaseCho()
        {
            //분이 59분 초과면
            if (chos > 59)
            {
                chos = 0;
            }
            else
            {
                chos++;
            }
        }
        private void IncreaseMinutes()
        {
            //분이 59분 초과면
            if (minutes > 59)
            {
                minutes = 0;
            }
            else
            {
                minutes++;
            }
        }
        public void StopWatch_Tick(object sender, EventArgs e)
        {
            ShowTime();
            IncreaseSecond();
        }
        public void Btn_Start_Click(object sender, EventArgs e)
        {
            if (this.Btn_Start.Text.Equals("시작"))
            {
                this.Btn_Start.Text = "멈춰";
                timer1.Enabled = true;
                timer1.Interval = 1;
                //타이머 Tick 이벤트

                timer1.Tick += StopWatch_Tick;
            }
            else
            {
                this.Btn_Start.Text = "시작";
                timer1.Enabled = false;
            }
        }
        public void Btn_Reset_Click(object sender, EventArgs e)
        {
            //분, 초 초기화
            chos = 0;
            seconds = 0;
            minutes = 0;
            ShowTime();
            if (!timer1.Enabled)
            {
                record.Items.Clear();
            }
        }
        private void ShowTime()
        {
            Lb_cho.Text = chos.ToString("00");
            Lb_Second.Text = seconds.ToString("00");
            Lb_Minutes.Text = minutes.ToString("00");
        }
        private void Btn_Save_MouseDown(object sender, MouseEventArgs e)
        {
            record.Items.Add(this.Lb_Minutes.Text + ":" + this.Lb_cho.Text + "." + this.Lb_Second.Text);
        }
    }
}

'프로그래밍 > C#' 카테고리의 다른 글

예외처리  (0) 2022.01.24
C# CRUD프로그램 + SQL 연동  (0) 2022.01.20
데이터 그리드뷰 위로 보내서 업데이트하기  (0) 2022.01.17
데이터그리드뷰 csv파일불러오기  (0) 2022.01.17
구구단  (0) 2022.01.17