基本信息
源码名称:C#倒计时器(入门篇)
源码大小:0.07M
文件格式:.rar
开发语言:C#
更新时间:2021-08-14
   友情提示:(无需注册或充值,赞助后即可获取资源下载链接)

     嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):78630559

本次赞助数额为: 2 元 
   源码介绍

    public partial class Form1 : Form
    {
        int count;//用于定时器计数
        int time;//存储设定的定时值
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            int i;
            for (i = 1; i < 100; i )//计数范围(0-99)
            {
                comboBox1.Items.Add(i.ToString() " 秒");//初始化下拉框内容(数字后加一个空格便于程序处理)
            
            }
            comboBox1.Text = "1 秒";
        }

        private void timer1_Tick(object sender, EventArgs e)//定时器事件
        {
            count ;//记当前秒
            label3.Text = (time - count).ToString() "秒";//显示剩余时间
            progressBar1.Value = count;//设置进度条进度
            if (count == time)
            {
                timer1.Stop();//时间到,停止计时
                System.Media.SystemSounds.Asterisk.Play();//提示音
                MessageBox.Show("时间到了!!!","提示!!");//弹出提示框
            }
        }

        private void button1_Click(object sender, EventArgs e)//开始计时按钮事件
        {
            string str = comboBox1.Text;//将下拉框内容添加到一个变量中
            string data = str.Substring(0, 2);
            time = Convert.ToInt16(data);//得到设定定时值(整形)
            progressBar1.Maximum = time;//进度条最大数值
            timer1.Start();//开始计时
        }