如何使用计时器? [英] how to use the timers?

查看:82
本文介绍了如何使用计时器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在第一次加载表单后运行5个小时.
我如何检查开始运行表单需要多长时间?
"time< 5"这个条件是不可接受的,我该如何更改它以获得时间值?
请帮帮我.

私有void mainpg_Load(对象发送者,EventArgs e)
{
DateTime时间= timer1.Start();
如果(时间< 5)
{
//保持相同的形式
main_test一个=新的main_test();
one.MdiParent = main.ActiveForm;
one.Show();
}
否则if(time> = 5)
//从应用程序退出.
}

解决方案

您尝试实现的方法是错误的.

此处查看文档. msdn.microsoft.com/zh-cn/library/system.windows.forms.timer.aspx"target =" _ blank"title =" New Window> ^ ]


i need to run a form for 5 hours from the first form load.
how can i check how long is it being started to run the form?
"time< 5" this condition is not acceptable,how can i change this in order to get the time value?
please help me.

private void mainpg_Load(object sender, EventArgs e)
{
DateTime time=timer1.Start();
if (time< 5)
{
//remain in the same form
main_test one = new main_test();
one.MdiParent = main.ActiveForm;
one.Show();
}
else if(time >= 5)
//exit from the application.
}

解决方案

The way you are trying to implement is wrong.

Check the documentation here[^]


这篇关于如何使用计时器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆