如何在 Windows 窗体应用程序中跟踪 C# 中两次按钮单击之间的时间? [英] How to track time between two button clicks in C# in a Windows form application?
本文介绍了如何在 Windows 窗体应用程序中跟踪 C# 中两次按钮单击之间的时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在 c# 中创建了一个 windows 窗体应用程序,其中从用户那里获取输入.我想计算用户在两次提交之间花费的时间.我该怎么做?
I have created a windows form application in c# in which input from user is taken .I want to calculate time spent by user in between two submissions.How can I do that?
推荐答案
使用 秒表.在类级别创建秒表的对象并使用它来计算时间.
Use Stopwatch. Create object of the Stopwatch at class level and use that to calculate time.
类似于:
public partial class Form1 : Form
{
Stopwatch stopwatch = new Stopwatch();
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
stopwatch.Start();
}
private void button2_Click(object sender, EventArgs e)
{
stopwatch.Stop();
var milliSeocnds = stopwatch.ElapsedMilliseconds;
var timeSpan = stopwatch.Elapsed;
}
}
这篇关于如何在 Windows 窗体应用程序中跟踪 C# 中两次按钮单击之间的时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文