日期:2014-05-17  浏览次数:20775 次

利用timer计时,并根据if语句判断是否合格
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 WindowsFormsApplication2
{
    public partial class Form1 : Form
    {
        //1,计时的程序代码
        Timer t = new Timer();
        DateTime startTime;
        TimeSpan span = new TimeSpan();
        public Form1()
        {
            t.Tick += new EventHandler(t_Tick);
            t.Interval = 10;
            InitializeComponent();
        }

        void t_Tick(object sender, EventArgs e)
        {
            span = DateTime.Now - startTime;
            textBox1.Text = String.Format("分:{0}秒:{1}", span.Minutes, span.Seconds);
        }

        private void Form1_Load(object sender, EventArgs e)
        {

            t.Start();
            startTime = DateTime.Now;//在启动时间控件时给初始时间赋值
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {

        }
        
        
        
        // 2,设计一段程序,经if语句后,弹出消息框提示:在t=   时不合格或者合格//


        public static int Main()
        {