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 WindowsFormsApplication1
{ public partial class Form12 : Form {public enum RunState
{ running, pause, stop }private int i = 0;
RunState state = RunState.stop;
public Form12() { InitializeComponent(); }private void RunProc(object sender, EventArgs e)//执行的部分
{ timer1.Enabled = false; if (state == RunState.running) { label1.Refresh(); label1.Text = ""; label1.Text = i.ToString(); label1.Refresh(); i++; timer1.Enabled = true; } }private void button1_Click(object sender, EventArgs e)
{ if (this.button1.Text == "开始") { this.button1.Enabled = false; this.button2.Enabled = true; this.button3.Enabled = true;timer1.Tick += new EventHandler(RunProc);
timer1.Enabled = true;this.state = RunState.running;
} }private void button2_Click(object sender, EventArgs e)
{ if (this.button2.Text == "暂停") { timer1.Enabled = false; state = RunState.pause;this.button2.Text = "继续";
} else { timer1.Enabled = true; this.state = RunState.running; this.button2.Text = "暂停"; this.button2.Enabled = true; //timer1.Start(); }}
private void button3_Click(object sender, EventArgs e)
{ this.timer1.Enabled = false; this.i = 0; this.label1.Text = "0"; this.state = RunState.stop;this.button1.Text = "开始";
this.button1.Enabled = true; this.button2.Text = "暂停"; this.button2.Enabled = false; this.button3.Enabled = false;}
private void Form12_Load(object sender, EventArgs e)
{ this.label1.Text = "0"; this.button2.Enabled = false; this.button3.Enabled = false; } }}