namespace _5.小闹钟程序
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
//注册个timer事件
private void timer1_Tick(object sender, EventArgs e)
{
//每隔一秒将当前的时间赋值给label
//label是字符串类型,所以需要将时间转换为字符串类型
label1.Text = DateTime.Now.ToString();
//6:30分播放音乐叫我起床
if(DateTime.Now.Hour==6 && DateTime.Now.Minute == 30 &&DateTime.Now.Second==00)
{
//新建播放音乐对象
SoundPlayer sp = new SoundPlayer();
//播放音乐路径,这里支持wav格式
sp.SoundLocation = @"C:\Users\Administrator.USER-20180925HC\Desktop\1.wav";
//到6:30分自动播放音乐
sp.Play();
}
}

    private void Form1_Load(object sender, EventArgs e)
    {
        //第一秒的时间,当程序加载时就加载
        label1.Text = DateTime.Now.ToString();
    }
}

}