C# 視窗程式範例 -- Timer 的使用 -- 短跑用碼表

專案下載:TimerClock.zip

檔案:FormClock.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 TimerClock
{
    public partial class FormClock : Form
    {
        int counter = 0;
        public FormClock()
        {
            InitializeComponent();
            timer.Enabled = true;
        }
        private void timer_Tick(object sender, EventArgs e)
        {
            DateTime now = DateTime.Now;
            labelTime.Text = now.Hour + ":" + now.Minute + ":" + now.Second;
            if (isStart) {
                counter++;
                labelCounter.Text = (counter / 100.0) + "";
            }
        }
        bool isStart = false;
        private void buttonStart_Click(object sender, EventArgs e)
        {
            isStart = !isStart;
            if (isStart)
            {
                buttonStart.Text = "停止計時";
            }
            else
            {
                buttonStart.Text = "開始計時";
            }
        }
    }
}
	

執行結果

TimerClockCounter.jpg

文章來源:陳鍾誠 (2011年10月25日),(網頁標題) Timer 的使用 — 短跑用碼表,(網站標題) 免費電子書:C# 程式設計,2011年10月25日,取自 http://cs0.wikidot.com/timerclockcounter ,網頁修改第 2 版。


arrow
arrow

    Johnson峰 發表在 痞客邦 留言(0) 人氣()