请牛人帮忙 
   我做个C/S模式的考试系统,用timer控件进行时间上的限制,可是每次都不执行这个代码,找了半天,百度也百了半天,还是不知道错在哪里,麻烦知道的说下这个timer控件的用法 或者一些实例代码

解决方案 »

  1.   

    timer 设置 interval 属性为 60000 enabled 属性为 true在窗体代码添加一个局部变量:
    int minutes = 0;在 timer_tick() 编写
    {
        minutes++;
        if (minutes >= 120) MessageBox.Show( "120分钟,考试时间到了" );
    }
      

  2.   


    timer控件的Enabled属性缺省是设置为false的,lz看看是不是这个开关没有打开,呵呵。
      

  3.   

    public void timer1_Tick(object sender, EventArgs e)
            {
                this.timer1.Start();
                timer1.Interval = 1000;
                timer1.Enabled = true;
               
                int sumsecond = 60;
                int minute, second;
               
                sumsecond--;
                if (sumsecond > 0)
                {
                    sumsecond--;
                    minute = sumsecond / 60;
                    second = sumsecond % 60;
                    // lblTime.Text = string.Format("{0:00}:{1:00}", minute, second);   
                }            else
                {                checkForm checkform = new checkForm();
                    int i = checkform.chkAnswer();                DialogResult result = MessageBox.Show("您的得分为" + i + "分" + "||" + "按确定退出考试系统");                string connStr = "server=yuanmh;Integrated Security=true;Data Source=(local);database=MySchool;";
                    string strinsert = "update Student set result=" + i + " where  loginid='" + denglu.textBox_1.Text + "'and loginpwd='" + denglu.textBox_2.Text + "'";
                    SqlConnection conn = new SqlConnection(connStr);
                    SqlCommand cmd = new SqlCommand(strinsert, conn);
                    conn.Open();
                    cmd.ExecuteNonQuery();
                    conn.Close();                if (result == DialogResult.OK)
                    {
                        Environment.Exit(0);
                    }            }
            }这是我的代码 麻烦各位看下 是不是哪里错掉了
      

  4.   

    this.timer1.Start();这一行不应该放在Tick事件里面执行,Start相当于一个启动开关,而Tick是启动之后执行的事情。逻辑悖了。你在外部找一个地方执行一下Start试试吧,哪怕是添加一个按钮执行,先试试效果。
      

  5.   

    还是不行 我家了一个button按钮去执行,没反应,有什么类似的代码吗 给我看看
      

  6.   

    MSDN有例子// 1. 定义一个timer变量
    private System.Timers.Timer testTimer;// 2. 在构造函数中给timer注册处理函数
    testTimer.Elapsed += new System.Timers.ElapsedEventHandler(testTimer_Elapsed);// 3. 在开始考试的地方启动计时器
    testTimer.start();// 4. 写计时器到时间后的处理代码
    void testTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
    {
       // 这里写计时器到时间后的代码
    }