U E D R , A S I H C RSS

데블스캠프2012/넷째날/묻지마Csharp/Mission3/김수경 (rev. 1.2)

데블스캠프2012/넷째날/묻지마Csharp/Mission3/김수경

  • Form2.cs

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace DevilsCamp
{
    public partial class Form2 : Form
    {
        private Time time = new Time();
        public Form2()
        {
            InitializeComponent();
        }

        private void startBtn_Click(object sender, EventArgs e)
        {
            if (!timer1.Enabled)
            {
                timer1.Enabled = true;
                startBtn.Text = "Pause";
            }
            else
            {
                timer1.Enabled = false;
                startBtn.Text = "Start";
            }
        }

        private class Time
        {
            public int hour;
            public int minute;
            public int second;
            public int milli;

            public void tick()
            {
                tickMilli();
            }

            private void tickMilli()
            {
                if (++milli == 10)
                {
                    milli = 0;
                    tickSecond();
                }
            }

            private void tickSecond()
            {
                if (++second == 60)
                {
                    second = 0;
                    tickMinute();
                }
            }

            private void tickMinute()
            {
                if (++minute == 60)
                {
                    minute = 0;
                    tickHour();
                }
            }

            private void tickHour()
            {
                hour++;
            }
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            time.tick();
            display();
        }

        private void display() {
            hour.Text = string.Format("{0:D2}", time.hour);
            minute.Text = string.Format("{0:D2}", time.minute);
            second.Text = string.Format("{0:D2}", time.second);
            milli.Text = string.Format("{0}", time.milli);
        }

        private void stopBtn_Click(object sender, EventArgs e)
        {
            time = new Time();
            timer1.Enabled = false;
            display();
            listBox1.Items.Clear();
        }

        private void recordBtn_Click(object sender, EventArgs e)
        {
            listBox1.Items.Add(string.Format("{0:D2}:{1:D2}:{2:D2}.{3}", time.hour, time.minute, time.second, time.milli));
        }

    }
}


Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:29:14
Processing time 0.0387 sec