计时器过去后执行操作

时间:2014-09-30 16:42:02

标签: c#

我想发出一声嘟嘟声,表示我的计时器已经过去了。我会把代码放在哪里,以便在我的计时器到期时发生?

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 个答案:

答案 0 :(得分: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;

添加