在C#中使用计时器控件进行时间验证 [英] Time Validation using Timer Control in c#
本文介绍了在C#中使用计时器控件进行时间验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用Windows应用程序.
我以一种形式拖动了一个标签和一个计时器控件.
我编写了以下代码:-
表单加载事件:-
I am working on Windows Application.
In a form I dragged one label and one timer control.
I have written the following code:-
On form load event:-
Timer1.Start(); // Timer in initialized.
private void timer1_Tick(object sender, EventArgs e)
{
bool status = false;
label1.Text = DateTime.Now.ToLongTimeString();
DateTime time = Convert.ToDateTime("10:05:00 PM");
if (DateTime.Now.ToLongTimeString() == time.ToLongTimeString())
{
MessageBox.Show("Perfect Code.", "Timer Control", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
我在晚上10点运行程序,所以我进入了晚上10点.在当前时间之后输入时间.
该程序中的错误是,当用户时间等于系统时间时,Message Box会显示9次.帮我解决这个问题.
在此先感谢....
I was running program at 10 pm so I entered 10 pm. Enter the timing after the current time.
Error in this program is that when the user time is equal to system time Message Box is shown 9 times. Help me sort out this.
Thanks in Advance....
推荐答案
我将计时器控件的时间间隔设置为1000,现在只显示一次.
I set the time Interval of timer control to 1000, now it''s showing only once.
这篇关于在C#中使用计时器控件进行时间验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文