我有一個小問題。有像國際象棋計時器這樣的東西。當我按下按鈕時,當前計時器停止并秒開始,但在 1 秒后。我怎樣才能立即開始第二個?using System;using System.Windows.Forms;namespace WindowsFormsApp1 { public partial class Form1 : Form { byte sec1; byte sec2; public Form1() { InitializeComponent(); sec1 = 0; sec2 = 0; } private void button1_Click(object sender , EventArgs e) { timer1.Start(); timer2.Stop(); } private void button2_Click(object sender , EventArgs e) { timer2.Start(); timer1.Stop(); } private void timer1_Tick(object sender , EventArgs e) { label1.Text = sec1.ToString(); sec1++; } private void timer2_Tick(object sender , EventArgs e) { label2.Text = sec2.ToString(); sec2++; } }}
2 回答

繁星coding
TA貢獻1797條經驗 獲得超4個贊
計時器會立即啟動。問題是您沒有報告幾分之一秒,因此顯示將顯示0直到整整一秒過去,這在技術上是準確的。
如果您想1立即顯示,只需以這種方式初始化您的變量。
public Form1() {
InitializeComponent();
sec1 = 1;
sec2 = 1;
}
- 2 回答
- 0 關注
- 188 瀏覽
添加回答
舉報
0/150
提交
取消