我想添加一个计时器而不是一个自动开始的倒计时 表格加载。开始时间应为 45 分钟,一旦结束,即达到 0 分钟时,表单应终止并显示一条消息。我该怎么做?
语言:最好是C#。
最佳答案
更多细节:
private void Form1_Load(object sender, EventArgs e)
{
Timer MyTimer = new Timer();
MyTimer.Interval = (45 * 60 * 1000); // 45 mins
MyTimer.Tick += new EventHandler(MyTimer_Tick);
MyTimer.Start();
}
private void MyTimer_Tick(object sender, EventArgs e)
{
MessageBox.Show("The form will now be closed.", "Time Elapsed");
this.Close();
}
关于c# - 将计时器添加到 Windows 窗体应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1142828/