计时器 - 经过特定时间后显示消息 [英] Timer - Show a message after a specific time has passed
本文介绍了计时器 - 经过特定时间后显示消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的表单上有一个计时器,它显示当前时间(基于我的系统)我想要做的是例如当前时间是6:22 PM"所以当它到达6:24 PM"时它应该显示一条消息您必须提交报告"我该怎么做?这是我的代码.
I have got a timer on my form like and it shows the current time (based on my system) what i want to do is for example current time is "6:22 PM" so when it reaches "6:24 PM" it should show a Message as "You have to submit a report" how do i do? Here is my code.
private void timer1_Tick(object sender, EventArgs e)
{
label1.Text = DateTime.Now.ToString("MM-dd-yyyy hh:mm:ss tt");
}
这只是显示当前时间.有人可以帮我处理这个消息框"吗?
This just shows the current time.Can someone help me on this "message box"?
推荐答案
timer1 的时间间隔是多少?可能是 1000 毫秒,即 1 秒.假设1秒时间间隔,添加条件
what is time interval of timer1 ? Probably its 1000 ms i.e. 1 sec. Assuming 1 sec time interval, add a condition
private DateTime showOnDate = DateTime.Today;
private void timer1_Tick(object sender, EventArgs e)
{
label1.Text = DateTime.Now.ToString("MM-dd-yyyy hh:mm:ss tt");
if (DateTime.Now.Hour == 18 && DateTime.Now.Minute == 24 && showOnDate == DateTime.Today)
{
showOnDate = DateTime.Today.AddDays(1);
MessageBox.Show("You have to submit a report");
}
}
这篇关于计时器 - 经过特定时间后显示消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文