时间控件

一个是利用时间控件实现图片的动画的效果,还有一个是考试答题的计时器供你参考

下面的这段代码是利用时间控件让pictureBOX控件中的图片实现动画效果

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace MySchool
{
    public partial class AboutForm : Form
    {
        int index = 0;
        public AboutForm()
        {
            InitializeComponent();
        }

        private void tmrTime_Tick(object sender, EventArgs e)
        {
           
            if (index < ilAbout.Images.Count - 1)
            {
                index++;
            }
            else
            {
                index = 0;
            }
            picAbout.Image = ilAbout.Images[index];
        }

private void button1_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}

下面的代码是考试计时器
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace MySchool
{
    public partial class AnswerCardForm : Form
    {
        public AnswerCardForm()
        {
            InitializeComponent();
        }

        // 计时器的 Tick 事件
        private void tmrCostTime_Tick(object sender, EventArgs e)
        {
            int minute;   // 当前的分钟
            int second;   // 秒

            // 如果还剩有答题时间,就显示剩余的时间
            if (QuizHelper.remainSeconds > 0)
            {
                minute = QuizHelper.remainSeconds / 60;
                second = QuizHelper.remainSeconds % 60;
                lblTimer.Text = string.Format("{0:00}:{1:00}", minute, second);  // 补充知识点
                QuizHelper.remainSeconds--;
            }
            // 否则,停止计时,提示交卷
            else
            {
                tmrCostTime.Stop();
                MessageBox.Show("时间到了,该交卷了!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                QuizResultForm quizResultForm = new QuizResultForm();
                quizResultForm.Show();
                this.Close();
            }
        }

posted on 2009-05-13 15:53  大胡子青松  阅读(273)  评论(0编辑  收藏  举报

导航