zoukankan      html  css  js  c++  java
  • C# winfrom设置循环暂停和继续 原文转自:http://blog.csdn.net/qwldcl/article/details/3970784

    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;
            }
        }
    }

  • 相关阅读:
    打sql server pack4后打开网站报错的解决办法
    北京大学的三角形文章
    一次SQL Server 2000修复实践的说明
    今天重看了几集《将爱情进行到底》
    MakeFile的写法
    [经验杂谈]与大虾对话:领悟设计模式zz
    论函数调用约定(zz)
    用标准模板库STL实现文件比较(zz)
    C++中的虚函数(virtual function)
    为学院科研办做的个小应用管理程序
  • 原文地址:https://www.cnblogs.com/wuhuisheng/p/2133466.html
Copyright © 2011-2022 走看看