namespace naozhong
{
public partial class Form1 : Form
{
NaoZhong naozhong = new NaoZhong();
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)//浏览的按钮
{
DialogResult result=openFileDialog1.ShowDialog();//打开文件
if(result.ToString()=="Ok")//如果是打开的情况下
{
txtbgsound.Text = openFileDialog1.FileName;
}
}
private void button2_Click(object sender, EventArgs e)//确定按钮
{
naozhong.Time=Convert.ToDateTime(txttime.Text).ToString("yyyy-MM-dd hh:mm:ss");
naozhong.bgsound = txtbgsound.Text;
MessageBox.Show("设置成功");
}
private void timer1_Tick(object sender, EventArgs e)
{
if(naozhong.play()==true)
{
axWindowsMediaPlayer1.URL = naozhong.bgsound;
axWindowsMediaPlayer1.Ctlcontrols.play();
}
}
}
NaoZhong类中
public class NaoZhong
{
public string Time { get; set; }
public string bgsound { get; set; }
public bool play()
{
if (Time == DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"))
{
return true;
}
return false;
}
}