倒计时

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 倒计时
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            timer1.Interval = 800;
        }
        int a = 10;

        private void button1_Click(object sender, EventArgs e)
        {
            if (timer1.Enabled)
            {
                timer1.Stop();
                button1.Text = "开始";
            }
            else
            {
                timer1.Start();
                button1.Text = "暂停";
            }
        }
        private void timer1_Tick(object sender, EventArgs e)
        {
            a--;
            if (a < 4)
            {
                label2.ForeColor = Color.Red;
            }
            else
            {
                label2.ForeColor = Color.Green;
            }
            if (a < 0)
            {
                timer1.Stop();
                button1.Text = "开始";
            }
            else
            {
                label2.Text = a.ToString();
            }
            
        }

        private void button2_Click(object sender, EventArgs e)
        {
            a = 10;
            label2.Text = a.ToString();
        }
        
    }
}

  

 

posted @ 2024-07-12 15:55  fushuxuan1  阅读(23)  评论(0)    收藏  举报