将计时器添加到Windows窗体应用程序
我想添加一个计时器而不是倒计时,它会在表单加载时自动启动。 开始时间应为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(); }
你的forms主要是这样的东西。 双击可视化编辑器中的表单以创建表单加载事件。
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 } }
下载https://download.cnet.com/Free-Desktop-Timer/3000-2350_4-75415517.html
然后在表单上和事件内添加一个按钮或其他内容,只需打开此应用程序,即:
{
Process.Start(@“C: Program Files(x86) Free Desktop Timer DesktopTimer”);
}
上述就是C#学习教程:将计时器添加到Windows窗体应用程序分享的全部内容,如果对大家有所用处且需要了解更多关于C#学习教程,希望大家多多关注—计算机技术网(www.ctvol.com)!
本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。
ctvol管理联系方式QQ:251552304
本文章地址:https://www.ctvol.com/cdevelopment/1026304.html