当前位置:   article > 正文

C# 自定义定时器的开启、暂停、继续_c# timer暂停

c# timer暂停

一、创建定时器

private System.Windows.Forms.Timer timerGetTime = new System.Windows.Forms.Timer();//创建定时器

public enum RunState//按钮状态 1运行中 2暂停  3停止
        {
            running,
            pause,
            stop
        }

RunState runstate = RunState.stop;

二、初始化定时器设值

 //设置定时器属性
 timerGetTime.Interval = 5000; //间隔时间
 timerGetTime.Enabled = false;//先不开启
 //定时器关联事件
 timerGetTime.Tick += new EventHandler(TimeExecute);

三、点击开启按钮

private void button1_Click(object sender, EventArgs e)//开启按钮
        {

            button2.Text = "暂停";//暂停继续按钮
            button2.Enabled = true;//暂停继续按钮禁用

            timerGetTime.Enabled = true;

            timerGetTime.Start();

            runstate = RunState.runni

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Monodyee/article/detail/436542
推荐阅读
相关标签
  

闽ICP备14008679号