search
尋找貓咪~QQ 地點 桃園市桃園區 Taoyuan , Taoyuan

C# Timer 如何啟動,暫停,停止 – jashliao部落格

C# Timer 如何啟動,暫停,停止 

 

資料來源:http://www.programmer-club.com.tw/ShowSameTitleN/csharp/11566.html

 

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 WindowsFormsApplication20
{
    public partial class Form1 : Form
    {
     Timer _timer = new Timer();
     int startValue,endValue,currentValue,totalValue; 

     public Form1()
     {
     InitializeComponent();
     _timer.Tick += new EventHandler(_timer_Tick);
     startValue = 0;
     endValue = 100;

     }

     void _timer_Tick(object sender, EventArgs e)
     {
     totalValue += currentValue;
     this.Text = totalValue.ToString();
     if (currentValue >= endValue)
     {
     button2.PerformClick();
     return;
     }
     currentValue++;
     }

     private void button1_Click(object sender, EventArgs e)
     {
     _timer.Interval = 100;
     _timer.Start();
     }

     private void button2_Click(object sender, EventArgs e)
     {
     _timer.Stop();
     totalValue = 0;
     currentValue = 0;
     this.Text = totalValue.ToString();
     }

     private void button3_Click(object sender, EventArgs e)
     {
     _timer.Enabled = !_timer.Enabled;
     }
    }
}

 

 



熱門推薦

本文由 jashliaoeuwordpress 提供 原文連結

寵物協尋 相信 終究能找到回家的路
寫了7763篇文章,獲得2次喜歡
留言回覆
回覆
精彩推薦