zoukankan      html  css  js  c++  java
  • C#倒计时

    示意图:六个lable,三个文本框,一个but即可  timer控件或自定义一个

    以下是代码实现的部分

    public int ConvertInt32(string name)
            {
                if (name != "" && name != null)
                {
                    return Convert.ToInt32(name);
                }
                else
                {
                    return 0;
                }
            }
            int Hose, Minut, Second = 0;
            //public void ComdTimer()
            //{
            //    if (button1.Text == "设置")//判断按钮的文本是否为设置
            //    {
            //        button1.Text = "停止";//设置按钮的文本为停止
            //        timer2.Start();//启动timer2计时器
            //    }
            //    else if (button1.Text == "停止")//判断按钮的文本是否为停止
            //    {
            //        button1.Text = "设置";//设置按钮的文本为设置
            //        timer2.Stop();//停止timer2计时器
            //        label3.Text = "倒计时已取消";
            //    }
            //}
            
    
            private void button1_Click(object sender, EventArgs e)
            {
                Hose = ConvertInt32(textBox1.Text.Trim());
                if (ConvertInt32(textBox2.Text.Trim()) > 60)
                {
                    MessageBox.Show("不能大于60分钟");
                    return;
                }
                else
                {
                    Minut = ConvertInt32(textBox2.Text.Trim());
                }
                if (ConvertInt32(textBox3.Text.Trim()) >= 60)
                {
                    MessageBox.Show("不能大于60秒");
                    return;
                }
                else
                {
                    Second = ConvertInt32(textBox3.Text.Trim());
                }
                this.timer1.Start();
                this.timer1.Enabled = true;
            }
    
            private void timer1_Tick(object sender, EventArgs e)
            {
                if (Second != 0)
                {
                    Second--;
                    //给Viz发东西
                }
                if (Second == 0)
                {
                    if (Minut != 0)
                    {
                        Second += 60;
                        Minut--;
                    }
                }
                if (Minut == 0)
                {
                    if (Hose != 0)
                    {
                        Minut += 60;
                        Hose--;
                    }
                }
                label3.Text = Hose.ToString();
                label2.Text = Minut.ToString();
                label1.Text = Second.ToString();
            }
  • 相关阅读:
    flex>导航
    flex>图表控件
    Struts2>Cannot find the tag library descriptor for /strutstags
    jsp>Smartupload例子代码
    flex>MXML语法
    解决JBoss只能通过localhost(127.0.0.1)而不能通过IP访问
    jsp>tomcat配置虚拟目录
    JSF>概述
    Struts2>中文乱码
    flex>HttpService
  • 原文地址:https://www.cnblogs.com/xunmengrenli/p/15398556.html
Copyright © 2011-2022 走看看