如何制作固定报警器? [英] How to make a fixed alarm ?
本文介绍了如何制作固定报警器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想得到相同的结果但是在if条件下使用(日期时间)并计算剩余时间来报警。
感谢您的回复。
I would like to make the same result but by using (date time) in if condition and count the rest time to alarm.
Thanks for the reply.
using system.media;
//code in time tick
private void timer1_Tick(object sender, EventArgs e)
{
label2.Text = DateTime.Now.ToString("hh:mm:ss") + " " + DateTime.Now.ToString("tt");
}
//code in form_load
private void Form1_Load(object sender, EventArgs e)
{
soundplay snplayer= new soundplay (alarm_test.properties.resources.alarm);
if (label2.text=="06:00:00 AM")
snplayer.play();
}
推荐答案
您的代码存在一些问题。
There are a couple of things wrong with your code.
- 设置
label2
的文本应简化为:
- Setting the text of
label2
should be simplified to:
label2.Text = DateTime.Now.ToString("hh:mm:ss tt");
if
测试计时器滴答处理程序,如:if
test to the timer tick handler, as in:if (DateTime.Now.TimeOfDay == TimeSpan.FromHours(6)) {
snplayer.play();
}
警告:你仍然可以找到 sndplayer.play()
永远不会执行! 你能猜到为什么吗?
/ ravi
Warning: You may still find sndplayer.play()
will never execute! Can you guess why?
/ravi
这篇关于如何制作固定报警器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文