2014-09-30 29 views
-4

我想提供一聲蜂鳴聲以表明我的計時器已過。我將代碼放在哪裏,以便在我的計時器過期時發生?當計時器過去時執行操作

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

    private void timer1_Tick(object sender, EventArgs e) 
    { 
     Timer aTimer = new Timer(); 
     aTimer.Interval = 1000; 
     // Hook up the Elapsed event for the timer. 
     aTimer.Enabled = true; 
     aTimer.tick += OnTimedEvent; 
    } 

    private void OnTimedEvent(object sender, EventArgs e) 
    { 
     MessageBox.Show("process"); 
    } 
+1

你問如何創建系統嗶聲?如何顯示消息框?如何使用'Timer'?請具體說明,並說明你已經嘗試了什麼,以及它是如何工作的。 – David 2014-09-30 16:45:00

+0

假設這裏沒有人見過你的代碼,或者知道你的目標是什麼平臺,或者有關你的項目的任何其他實現細節或需求,或者到目前爲止你可能嘗試過的。因爲我們沒有。你能添加更多細節嗎? – 2014-09-30 16:45:22

+1

你剛剛問過關於消息框的問題[兩小時前](http://stackoverflow.com/questions/26123513/how-to-display-a-message-box-when-timer-elapses-in-c-尖銳),並在評論中指出你「明白了」。這個問題和這個問題之間發生了什麼? – 2014-09-30 16:47:44

回答

0
using System; 
using System.Collections.Generic; 
using System.ComponentModel; 
using System.Data; 
using System.Drawing; 
using System.Linq; 
using System.Text; 
using System.Threading.Tasks; 
using System.Windows.Forms; 
using System.Media; 

namespace delete 
{ 
    public partial class Form1 : Form 
    { 
     public Form1() 
     { 
      InitializeComponent(); 
      timer1.Enabled = true; 
      timer1.Interval = 1000; 
     } 

     private void timer1_Tick(object sender, EventArgs e) 
     { 
      SoundPlayer sp = new SoundPlayer(); 
      sp.Play(); 
     } 
    } 
} 

不要忘記用System.Media增加;