本文主要是介绍winfrom实现闹钟,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
后台代码:
Clock myClock = new Clock();
public Form1()
{
InitializeComponent();
}
private void btnBrowse_Click(object sender, EventArgs e)
{
DialogResult result = openFileDialog1.ShowDialog();
if (result.ToString() == "OK")
{
txtMusicPath.Text = openFileDialog1.FileName;
}
}
private void btnConfirm_Click(object sender, EventArgs e)
{
if (txtMusicPath.Text != "" && txtTime.Text != "")
{
myClock.confrimTime =Convert.ToDateTime(txtTime.Text).ToString("yyyy-MM-dd hh:mm:ss");
myClock.musicPath = txtMusicPath.Text;
MessageBox.Show("设定成功");
}
}
private void timer1_Tick(object sender, EventArgs e)
{
if (myClock.isPlay())
{
axWindowsMediaPlayer1.URL = myClock.musicPath;
axWindowsMediaPlayer1.Ctlcontrols.play();
}
}
引用的类
public class Clock
{public string confrimTime { set; get; }
public string musicPath { set; get; }
public bool isPlay()
{
if (confrimTime == DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"))
{
return true;
}
return false;
}
}
这篇关于winfrom实现闹钟的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!