如何让倒计时应用计算月数和天数 [英] How do I get the countdown app to count month and days

查看:110
本文介绍了如何让倒计时应用计算月数和天数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以让应用倒数几分钟和几秒钟



我尝试过:



I can make the app count down minutes and seconds

What I have tried:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Threading;

namespace count_down
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        private int time = 30;
        private DispatcherTimer timer; 
        public MainWindow()
        {
            InitializeComponent();
            timer = new DispatcherTimer();
            timer.Interval = new TimeSpan(0,0,1);
            timer.Tick += Timer_Tick;
            timer.Start();
        }

        public void Timer_Tick(object sender, EventArgs e)
        {
            if (time > 0)
            {

                if (time <= 20)
                {
                    if (time % 2 == 0)
                    {
                        tbCountDown.Foreground = Brushes.Orange;
                    }
                    else
                    {
                        tbCountDown.Foreground = Brushes.Orange;

                    }

                    if (time <= 10)
                    {
                        if (time % 2 == 0)
                        {
                            tbCountDown.Foreground = Brushes.Red;
                        }
                        else
                        {
                            tbCountDown.Foreground = Brushes.White;

                        }
                    }
                
                    time--;
                    tbCountDown.Text = string.Format("00:0{0}:{1}", time / 60, time % 60);
                }
                else
                {
                    time--;
                    tbCountDown.Text = string.Format("00:0{0}:{1}", time / 60, time % 60);

                }

            }
            else
            {
                timer.Stop();
                MessageBox.Show("BOOM!");
            }
        }

        private void button_Click(object sender, RoutedEventArgs e)
        {

            if (txtB.Text == string.Empty)
            {
                MessageBox.Show("Please enter value");
            }
            else
            {
                MessageBox.Show(txtB.Text);
            }
        }
    }
}

推荐答案

你可以创建一个 TimeSpan 包括几天:参见 TimeSpan构造函数(Int32,Int32,Int32,Int32)(系统) [ ^ ]。
You can create a TimeSpan that includes a number of days: see TimeSpan Constructor (Int32, Int32, Int32, Int32) (System)[^].


这篇关于如何让倒计时应用计算月数和天数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆