簡單計時器

public partial class Form1 : Form
    {
       TimeSpan ts = new TimeSpan(0, 0, 60);
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            label1.Visible = false;
            timer1.Interval = 1000;
            timer1.Enabled = true;
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            label1.Text = ts.Hours.ToString() + ":" + ts.Minutes.ToString() + ":" + ts.Seconds.ToString();
            label1.Visible = true;
            ts = ts.Subtract(new TimeSpan(0, 0, 1));

            if (ts.TotalSeconds<0.0)
            {
                timer1.Enabled = false;
                label1.Visible = false;
                MessageBox.Show("考試時間到,系統將強行交卷");
            }
        }

    }

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章