Thứ Bảy, 1 tháng 3, 2014

Thiết kế chương trình đồng hồ đếm ngược. Phục vụ gameshow

Link download: http://www.mediafire.com/download/1d2wgcm2y13fv29/DongHoDemNguoc.rar
(Đã cập nhật âm thanh tick của giây và chuông báo hết giờ)

1. Form

Form đang chạy: người dùng đưa sô phút vào, đưa số giây vào và nhấn nút bắt đầu. 

Khi kết thúc, hiện lên thông báo hết giờ.


Trong form có sử dụng đối tượng timer

2. Coding

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 DongHoDemNguoc
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        int nguong, phut, giay;
      
        private void timer1_Tick(object sender, EventArgs e)
        {
             if (giay == 0)
                {
                    giay = 59;
                    phut--;
                }
                else
                {
                   giay--;
                }
                this.label1.Text = phut + ":" + giay;
                nguong = nguong - 1;
                if (nguong == -1)
                {
                    lblThongBao.Text = "Hết giờ";
                    label1.Text = "0:0";
                    timer1.Enabled = false;
                }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            timer1.Enabled = true;
            timer1.Interval = 1000;
            phut = int.Parse(this.numSoPhut.Value.ToString());
            giay = int.Parse(this.numSoGiay.Value.ToString());
            nguong = phut * 60 + giay;
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }
    }

}

Không có nhận xét nào:

Đăng nhận xét