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

  • 相关阅读:
    石墨烯
    spring 安装
    orm 对象关系映射
    刷机问题
    环境必备
    spring 例子
    刷系统——黑屏问题
    android 文件下载
    c# 事件处理
    回忆测试广告理论
  • 原文地址:https://www.cnblogs.com/wuhuisheng/p/2133466.html
Copyright © 2011-2022 走看看