c# winform窗体,简单倒计时器,按下button后计时器开始运行的代码

作者&投稿:夔可 (若有异议请与网页底部的电邮联系)
C#Winform窗体中实现倒计时!求助!!!~

timer Interval属性设置1000
Enable 属性设置 true
tick 事件代码
string datediff = "";
TimeSpan ts1 =new TimeSpan(Convert.ToDateTime(textBox1.Text).Ticks);
TimeSpan ts2 = new TimeSpan(DateTime.Now.Ticks);
TimeSpan ts = ts1.Subtract(ts2).Duration();
int tsyear=Convert.ToInt32(ts.Days)/365;
datediff =ts.Days.ToString() + "天" + ts.Hours.ToString() + "小时"
+ts.Minutes.ToString()+ "分钟" + ts.Seconds.ToString() + "秒";
label3.Text = datediff;


只转化成到天 小时 分钟 秒 其他自己琢磨 呵呵

int lefttime; private void button1_Click(object sender, EventArgs e) { int minute; try { minute = int.Parse(this.textBox1.Text); } catch (System.Exception ex) { this.label1.Text = "输入错误"; return; } lefttime = minute * 60; this.timer1.Interval = 1000; this.timer1.Enabled=true; this.timer1.Start(); } private void timer1_Tick(object sender, EventArgs e) { this.label1.Text = "剩余时间" + lefttime.ToString()+"秒"; lefttime--; }

        private int totalSecond = 299;
        private int tenthSecond = 9;
        private void timer1_Tick(object sender, EventArgs e)
        {
            //---窗体添加一个Label,一个Button,一个Timer--------
            //---5分钟倒计时,---功能单一,还有其他需求可以提。
            int minute = totalSecond / 60;
            int second = totalSecond % 60;
            String str = minute.ToString() + ":" + second.ToString() + ":" + tenthSecond.ToString();
            label1.Text = str;
            tenthSecond--;
            if (tenthSecond == -1)
            {
                tenthSecond = 9;
                totalSecond--;
                if (totalSecond == -1)
                {
                    timer1.Enabled = false;
                    timer3.Enabled = false;
                    label1.Text = "时间到!";
                    label1.ForeColor = Color.FromArgb(255, 0, 0);
                }
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            timer1.Enabled = true;
        }


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 WPF01_倒计时
{
    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() + " 秒");//初始化下拉框内容
            }
        }

        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;//将下拉框内容添加到一个变量中
            time = Convert.ToInt16(str.Substring(0, 2));//得到设定定时值(整型)
            progressBar1.Maximum = time;//进度条的最大值
            timer1.Start();//开始计时
        }
    }
}

时间自己弄,以秒为单位




钟山区15129215436: C#Winform窗体中实现倒计时!求助!!! -
植兴兰达: 可以,使用定时器timer,用来计时, 在用 需要倒计的时间一减就可以了

钟山区15129215436: c# winform窗体,简单倒计时器,按下button后计时器开始运行的代码 -
植兴兰达: private int totalSecond = 299; private int tenthSecond = 9; private void timer1_Tick(object sender, EventArgs e) { //---窗体添加一个Label,一个Button,一个Timer-------- //---5分钟倒计时,---功能单一,还有其他需求可以提. int minute = ...

钟山区15129215436: 用C#窗体做一个简单的可以让用户自定义倒计时时间的程序 -
植兴兰达: private DateTime alarmTime; //线程运行标志位,退出前需要设成flase;private bool runFlag; private double sencends; private void btnStart_Click(object sender, EventArgs e){if (runFlag){//已经启动计时器,防重入return;}//获取设...

钟山区15129215436: 用C#怎么做一个倒计时器 -
植兴兰达: (1)首先创建两个窗体,在Form1窗体上添加一个Button按钮和一个timer组件,用来执行倒计时功能;在Form2中添加一个Label控件,用于显示倒计时. (2)在Form2窗体中定义一个公共变量curr_time,用于为Label控件赋值,

钟山区15129215436: C#窗体程序怎么实现指定时间的倒计时? -
植兴兰达: 用定时器控件,获得当前时间,然后用一个文本框获得天数,启动定时器就行了么

钟山区15129215436: C# 窗体项目中如何实现倒计时? -
植兴兰达: 用timer控件和一个文本框. 这是我写的代码://timer控件的tick事件private void tmrSend_Tick(object sender, EventArgs e){int second = int.Parse(lblSecond.Text.Trim());int minute = int.Parse(lblMinute.Text.Trim()); if (second > 0){second--...

钟山区15129215436: WinForm窗体,C#
植兴兰达: 方法很多种,主要能调用父窗体的隐藏,子窗体的显示即可.这里的方法很多种指的是窗体之间的通信实现或者最简单的方式通过委托或者直接传递对象进行.这里只跟你说最简单的,对象传递,通过构造函数去处理.这里注意一下,这个是隐藏任务栏,隐藏窗体.只能在任务管理器里看到.还有一些细节要处理的,就不细说了,只告诉你思路.form1代码form2代码form3代码如果对你有帮助,望采纳!还有疑问请追问,谢谢!

钟山区15129215436: c# winform 窗体样式设计
植兴兰达: 1.你会不会解析xml文件?这个你可以上网查查,或者看看MSDN,就是把值解析成对象,变成我们可以调用的变量值 2.根据读到的值来设置你要改变的东西.但通常的做法是固定的那几项东西,比如背景色,字体,字号,要做到html(网页)...

钟山区15129215436: C# 计时器怎样倒计时;在label中显示.说得简单一点,只是初学D.
植兴兰达: 1)拖拽一个Timer控件到窗体上.设置Interval=1000,同时设置Enabled=True;拖拽一个Timer到窗体上. 2)双击这个Timer 3)编写如下代码(注意黑色部分) public class Form1 {…… private int totalCount = 10;…………private void Timer...

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 星空见康网