想在窗体里做一个计时器。。显示从打开这个窗体到现在的秒数,秒数精确到一秒。。

解决方案 »

  1.   

    Timer难道不行吗?设置Interval为1000
      

  2.   


    窗体添加Timer 控件
    设置Interval为1000
       int num =0;    //  放事件外面
    //  Tick 事件
      private void timer1_Tick(object sender, EventArgs e)
            {
                //toolStripStatusLabel3 是你要显示的标签名
                //this.toolStripStatusLabel3.Text = "当前时间:"+DateTime.Now.ToString();
                this.toolStripStatusLabel3.Text = "已打开时间:" + num.ToString() + "秒";
                num++;
            }
      

  3.   

    在窗体的Load事件里,timer.start()开启时钟,即打开窗口开始计时,timer的interval属性设置1000,即1秒设置个变量i初始值为0,时钟的tick事件里,i++,即每过一秒i加一,然后弄个控件显示i值就行了大致思路就是这样
      

  4.   

    在窗体Form的load末尾timer控件的属性Enabled=true;其他同上  就是不知思路有没问题,可能有误差……
      

  5.   

    Timer 有多个 Form下面的那个Timer不准 
    你用Thread里的那个
      

  6.   

    系统有timer
    Forms.Timer
    Threading.Timer
    Timers.Timer
    如果你觉得不爽,可以自己实现个timer
    新建控制台程序,用如下代码替换Program.cs中的所有内容,运行即可。using System;
    using System.Windows.Forms;
    using System.Threading;namespace CSharpConsole03
    {
        class Program
        {        public class Form1 : Form
            {
                protected override void OnLoad(EventArgs e)
                {
                    base.OnLoad(e);
                    StartTimer((EventHandler)delegate { DoSomething(); }, 1000);
                }
                bool running = false;
                public void StartTimer(Delegate d, int interval)
                {
                    running = true;
                    new Thread((ThreadStart)delegate
                    {
                        while (running && !this.IsDisposed)
                        {
                            Thread.Sleep(interval);
                            try
                            {
                                this.Invoke(d);
                            }
                            catch (InvalidOperationException)
                            {
                                //skip this exception
                            }
                        }                    
                    }).Start();
                }            public void StopTimer()
                {
                    running = false;
                }            public void DoSomething()
                {
                    this.Text = DateTime.Now.ToString("YYYY-MM-dd HH:mm:ss");
                }
            }        static void Main(string[] args)
            {
                Application.Run(new Form1());
                Console.ReadKey();
            }
        }
    }