我想添加一个计时器而不是倒计时,它会在表单加载时自动启动。起始时间应为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();
}
Timer Clock=new Timer();
Clock.Interval=2700000; // not sure if this length of time will work
Clock.Start();
Clock.Tick+=new EventHandler(Timer_Tick);
public void Timer_Tick(object sender,EventArgs eArgs)
{
if(sender==Clock)
{
// do something here
}
}
下载 http://download.cnet.com/Free-Desktop-Timer/3000-2350_4-75415517.html
然后在表格上添加一个按钮或其他控件,在其事件内打开这个应用程序 例如:
{
Process.Start(@"C:\Program Files (x86)\Free Desktop Timer\DesktopTimer");
}