想做个计时器软件   就是 输入一个时间 然后开始倒计时   可是不知道怎么做  麻烦高手指点下!

解决方案 »

  1.   


    class Program
        {
            static void Main(string[] args)
            {
                //dt中存放你的时间,可以把需要的时间转换成一个秒数,这里设定为10秒
                DateTime dt=new DateTime(10);
                long ticks = dt.Ticks;            while (true)
                {
                    System.Threading.Thread.Sleep(1000 * 1);
                    if (ticks == 0)
                    {
                        break;
                    }
                    else
                    {
                        ticks--;
                    }
                    Console.WriteLine("test:" + ticks);
                }
                Console.WriteLine("game over");
                Console.ReadLine();
            }
        }
    拿控制台写的了!
      

  2.   

    DateTime endTime;
    DateTime start;private void Form1_Load(object sender, EventArgs e) 

    endTime= DateTime.Now.AddSeconds(30); 
    timer1.Enabled = true; 

    private void timer1_Tick(object sender, EventArgs e) 

    DateTime show = start.Subtract(new TimeSpan(DateTime.Now.Ticks)); 
    label1.Text = show.ToLongTimeString(); 
    }
      

  3.   

      public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
                       }
            int x;
            private void Form1_Load(object sender, EventArgs e)
            {
                
                this.timer1.Interval = 1000;
                        }         private void button1_Click(object sender, EventArgs e)
            {
                timer1.Start();
                x = int.Parse(textBox1.Text.Trim());
            }        private void timer1_Tick(object sender, EventArgs e)
            {
                try
                {
                    x--;
                    label1.Text = x.ToString();
                    if (x < 1)
                    {
                        this.timer1.Stop();
                    }            }
                catch (Exception ex)
                {
                    MessageBox.Show("输入整数");
                }
            }    }