【#文档大全网# 导语】以下是®文档大全网的小编为您整理的《C#倒计时程序》,欢迎阅读!
using System;
using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text;
using System.Windows.Forms;
namespace WindowsApplication3 {
public partial class Form1 : Form {
public Form1() {
InitializeComponent(); }
private int totalSecond; private int tenthSecond;
private void Form1_Load(object sender, EventArgs e) {
label1.Text = "5:00:0"; progressBar1.Value = 300; button2.Text = "暂停"; button2.Enabled = false;
label1.BackColor = Color.FromArgb(0,0,255);
label1.ForeColor = Color.FromArgb(255, 255, 255); }
private void button1_Click(object sender, EventArgs e) {
totalSecond = 299; tenthSecond = 9;
timer1.Enabled = true; button2.Enabled = true; button2.Text = "暂停";
label1.BackColor = Color.FromArgb(0, 0, 255); label1.ForeColor = Color.FromArgb(255, 255, 255); }
private void button2_Click(object sender, EventArgs e) {
if (this.button2.Text == "暂停") {
timer1.Enabled = false; button2.Text = "继续"; } else {
timer1.Enabled = true; button2.Text = "暂停"; } }
private void timer1_Tick(object sender, EventArgs e) {
int minute = totalSecond / 60; int second = totalSecond %60;
string str = minute.ToString() + ":" +second.ToString() +tenthSecond.ToString();
label1.Text = str; tenthSecond--;
if (tenthSecond == -1) {
tenthSecond = 9; totalSecond--;
if (totalSecond == -1) {
timer1.Enabled = false; button2.Enabled = false;
label1.BackColor = Color.FromArgb(255, 255, 255); label1.ForeColor = Color.FromArgb(255, 0, 0); label1.Text = "时间到"; } else {
progressBar1.Value = totalSecond; } } } } }
+ ":"
本文来源:https://www.wddqxz.cn/024644c7aa00b52acfc7ca8f.html