how to time restrict the user to input in text-box for only 2 minutes in C# form ???????? will we use local time or create our own time stop etc and how??
I am writing a typing speed test program and the formula for calculating Net speed and Gross speed require exact time..................like 2 minutes or 3 minutes or 4 minutes I have tried Datetime to store only time and then compare it with a +2(2 minutes from present time) value but the loop never ends
DateTime time = DateTime.Now;
string format = "mm";
format = time.ToString(format);
int form = (int.Parse(format) + 01);
int a=-1;
while(a!=form)
{
time = DateTime.Now;
a=int.Parse(time.ToString(format));
Console.Write(a.ToString());
}
Console.Write(time.ToString(format));
两分钟结束后,在窗体加载上创建一个计时器,并禁用文本框。
I remember there is a timer control in Toolbox. You can set the enabled(or isenable) property of the textbox to false when the timer reaches 2 min. Then the user can no longer input.
Continue to ask if you still can't make it.
Create a timer on your page.
private Timer aTimer;
when typing start
public void start()
{
// Create a timer with a two minutes interval.
aTimer = new System.Timers.Timer(120000);
// Hook up the Elapsed event for the timer.
aTimer.Elapsed += OnTimedEvent;
aTimer.Enabled = true;
}
private void OnTimedEvent(Object source, ElapsedEventArgs e)
{
aTimer.Enabled = false;
// do what you want .........
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.