窗口窗体中的定时器设置 [英] Timer setting in Window Form

查看:99
本文介绍了窗口窗体中的定时器设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我想了解C#编程中使用Window Form的定时器设置。

i想要了解如何连接2个定时器设置并计算总时间和秒。



我在哪里可以学到它?

你可以给我一个地址吗?

解决方案

取决于你想要做什么,但我怀疑计时器根本不是你想要的。

定期课程 [ ^ ]提供事件并允许您定期进行某些操作 - 它没有任何内容使用总时间和秒,因为它只涉及滴答之间的间隔:它发出事件信号的点和处理器方法中的代码自动运行。它也不准确 - 它取决于你的计时器滴答事件处理程序何时执行(它不是实时或甚至关闭)的其他内容。



我怀疑你想看的是秒表类 [ ^ ]没有提供任何事件,但是非常好(并且非常准确),可以指出做某事需要多长时间。



如果你想每隔一段时间做一些事情,或者你想限制用户做某事的时间,那么使用一个计时器,否则,你可能最好使用秒表。

最好的方法是自己做。这不是一个难题,你当然可以google它,在MSDN中阅读文档,尝试一些代码,如果你发现任何问题,请在这里发布问题。



只有令人困惑部分原因是程序员可以选择多个计时器。哪一个最适合你取决于你想用它做什么。但是你没有告诉我们。



但是先做一些阅读。


我做了c#Windows表单应用程序我希望这对你有所帮助

这与在线考试总时间计算有关......

 / *点击开始按钮时* / 
DateTime from = DateTime.Now;单击结束按钮时

/ * * /
DateTime to = DateTime.Now;

/ *总时间* /
TimeSpan total = to - from;

string totalime = to.ToString(t);

/ *以秒为单位* /
字符串totaltime = total.TotalSeconds.ToString();





如果你想在几分钟或几小时内有不同的方法,如totalminutes等


Hi
I want to learn about Timer Setting with Window Form in C# programming.
i want to learn about how to link with 2 Timers setting and calculate total time and seconds.

Where can i learn it ?
Can u give me address?

解决方案

Depends on what you are trying to do, but I suspect that Timers are not what you want at all.
The Timer class[^] provides events and allows you to do someting at regular intervals - it had nothing to do with "total time and seconds" because it is concerned only with an interval between "ticks": the point at which it signals an event and your code in teh handler method runs automattically. It also isn't that accurate - it depends what else is going on as to when your timer tick event handler executes (it isn't in "real-time" or even close).

What I suspect you want to look at is the Stopwatch class[^] which doesn;t provide any events but is very good (and nicely accurate) at workign out how long it took to do something.

If you want to do something at intervals, or you want to limit how much time users can take to do something, then use a Timer, otherwise, you are probably better off with a Stopwatch.


Best way would be to do it on your own. This is not difficult topic and you certainly can google it, read documentation in MSDN, try some code and if you find any problem, post the question here.

Only confusing part would be that there are several timers available for programmers to choose from. Which one is the best for you depends on what you want to do with it. But this you didn’t tell us.

But do some reading first.


i done it c# Windows form application i hope this will helpful for you
this is related to online exam total time calculation......

/* When click on start button */
DateTime from = DateTime.Now;
 
/* when click on end button */
DateTime to = DateTime.Now;
 
/* total time */
TimeSpan total = to - from ;
 
string totalime = to.ToString("t");
 
/* In seconds  */
string totaltime = total.TotalSeconds.ToString();



If you want in minutes or hours there is different methods like totalminutes etc


这篇关于窗口窗体中的定时器设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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