2014-09-30 3 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

시스템 경고음을 만드는 방법을 묻는 질문이 있으십니까? 메시지 상자를 표시하는 방법? '타이머 '를 사용하는 방법? 구체적으로하고 시도한 것을 보여주고 작동하지 않는 방법을 보여주십시오. – David

+0

여기에 아무도 당신의 코드를 본 적이 없다거나 당신이 목표로하고있는 플랫폼이나 당신의 프로젝트에 대한 다른 구현 세부 사항이나 요구 사항, 또는 지금까지 시도한 것을 알지 못한다고 가정하십시오. 왜냐하면 우리는하지 않습니다. 자세한 내용을 추가 할 수 있습니까? –

+1

방금 ​​[2 시간 전] 메시지 상자에 대한 질문을했습니다 (http://stackoverflow.com/questions/26123513/how-to-display-a-message-box-when-timer-elapses-in-c- 날카로운) 그리고 당신이 "그것을 얻었다"는 코멘트에 나타납니다. 그 질문과이 사이에 무슨 일이 있었습니까? –

답변

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를 사용하여 추가하는 것을 잊지 마세요;

관련 문제