0
當我的定時器達到秒數(10,20或30)時,我想要顯示一個消息框。這有效,但不是隻有1個消息框,9出現!我不知道爲什麼?程序打開9個消息框,而我只想要1
private void timer1_Tick(object sender, EventArgs e)
{
int hrs = sw.Elapsed.Hours, mins = sw.Elapsed.Minutes, secs = sw.Elapsed.Seconds;
label5.Text = "";
if (mins < 60)
label5.Text += "0" + mins + ":";
else
label5.Text += mins + ":";
if(secs < 60)
label5.Text += secs;
else if(secs < 60)
label5.Text += secs;
if (comboBox1.Text == "10 seconden") // maximale tijd per beurt instellen.
if (mins == 00 && secs == 10)
MessageBox.Show("Je tijd is op!");
if (comboBox1.Text == "20 seconden")
if (mins == 00 && secs == 20)
MessageBox.Show("Je tijd is op");
if (comboBox1.Text == "30 seconden")
if (mins == 00 && secs == 30)
MessageBox.Show("Je tijd is op");
我懷疑你有多個事件訂閱,請在創建/訂閱你的計時器的地方張貼一段代碼。附註:這裏有一些重複的代碼,考慮更簡單的邏輯。 –
問題已經解決:),我只需要將計時器間隔從100更改爲1000. –
爲什麼更改間隔會改變行爲? –