定时播音的简单实现(C#)

来源:互联网 发布:犀牛蟑螂淘宝店 编辑:程序博客网 时间:2024/04/28 05:18
 
用两个定时器来交替工作:timer1用来监控时间,如与设定时间相同,则发生触发事件,传递参数,暂停timer1使用,启用timer2工作,并且打开开关;timer2收到开关信息后,触发事件:启动timer1、关闭开关、关闭自身timer2、播音。
 
namespace WindowsApplication3
{
    public partial class Form1 : Form
    {
        bool tt=false;
        public Form1()
        {
            InitializeComponent();
        }
        private void timer1_Tick(object sender, EventArgs e)
        {
          //  DateTime d = new DateTime();
            string s = DateTime.Now.ToString("hh:mm:ss");
            string a = "10:02:30";
            if(s==a)
            {
                timer1.Enabled = false;
                tt = true;
                axWindowsMediaPlayer1.URL = "E:/MyC#/谢谢你的爱.mp3";
               
            }
           
            timer2.Enabled = true;
        }
        private void timer2_Tick(object sender, EventArgs e)
        {
            if(tt)
            {
                timer2.Enabled = false;
                tt = false;
                axWindowsMediaPlayer1.Ctlcontrols.play();
               
            }
           
            timer1.Enabled = true;
        }
    }
}
原创粉丝点击