2014-09-30 48 views
0

我給我的時間間隔爲100.當計時器過去時,顯示消息框但我的屏幕充滿消息框。我應該如何通過一個消息框指示定時器已過。 這裏是我的代碼...你能引導我到哪裏給停止計時器...如何在c計時器中顯示消息框

namespace timer1 
{ 
    public partial class Form1 : Form 
    { 
     public Form1() 
     { 
      InitializeComponent(); 
     } 

     private void timer1_Tick(object sender, EventArgs e) 
     { 
      Timer t = new Timer(); 
      t.Interval = 100; 
      timer1.Enabled = true; 
      timer1.Tick += new System.EventHandler(OnTimerEvent); 

     } 
     private void OnTimerEvent(object sender, EventArgs e) 
     { 

      MessageBox.Show("time over"); 

     } 

    } 
} 
+5

請發佈您的代碼,以便我們可以看到錯誤。 – 2014-09-30 14:38:36

+1

似乎您已經知道如何在計時器過去時顯示消息框。也許你打算問關於停止計時器? – 2014-09-30 14:40:59

+2

停止計時器*之前*你顯示消息框,而不是之後:) – 2014-09-30 14:41:05

回答

1

我想(只要你不提供代碼),在中斷服務程序:

public void YourTimer_Tick(object sender, EventArgs e) 
{ 
     YourTimer.Stop(); 
     MessageBox.Show("You message..."); 
} 
+0

謝謝......我明白了 – user3478065 2014-09-30 15:40:30