我有一个你必须点击的按钮,它可以测量反应时间。在2人模式中(玩家10点击15次,玩家2点击15次)。我用两个标签给出的时间。但是为什么labelSummary2的文本是另一个标签的文本? (我想在两个标签中得到反应时间,以便我能够比较它们......)
public Form1()
{
InitializeComponent();
_Stopwatch = new Stopwatch();
_Stopwatch2 = new Stopwatch();
_ReactionTimes = new List<TimeSpan>();
_ReactionTimes2 = new List<TimeSpan>();
}
private void txbStart_MouseClick(object sender, MouseEventArgs e)
{
if (Spielzuege2 >= 16)
{
_Stopwatch2.Reset();
_Stopwatch2.Start();
}
else
{
_Stopwatch.Reset();
_Stopwatch.Start();
}
}
private void btnRot_Click(object sender, EventArgs e)
{
if (Spielzuege2 >= 16)
{
_Stopwatch2.Stop();
_ReactionTimes2.Add(_Stopwatch2.Elapsed);
labelSummary2.Text = String.Format("Player 2: Current: {0:0.000} s Minimum: {1:0.000} s Maximum: {2:0.000} s", _ReactionTimes.Last().TotalSeconds, _ReactionTimes.Min().TotalSeconds, _ReactionTimes.Max().TotalSeconds);
}
else
{
_Stopwatch.Stop();
_ReactionTimes.Add(_Stopwatch.Elapsed);
labelSummary.Text = String.Format("Player 1: Current: {0:0.000} s Minimum: {1:0.000} s Maximum: {2:0.000} s", _ReactionTimes.Last().TotalSeconds, _ReactionTimes.Min().TotalSeconds, _ReactionTimes.Max().TotalSeconds);
}
}
答案 0 :(得分:1)
您使用_ReactionTimes
列表填充两个标签,而不是_ReactionTimes2
用于labelSummary2
:
labelSummary2.Text = String.Format("Player 2: Current: {0:0.000} s Minimum: {1:0.000} s Maximum: {2:0.000} s", _ReactionTimes.Last().TotalSeconds, _ReactionTimes.Min().TotalSeconds, _ReactionTimes.Max().TotalSeconds);
答案 1 :(得分:0)
替换按钮点击事件的以下代码:
private void btnRot_Click(object sender, EventArgs e)
{
if (Spielzuege2 >= 16)
{
_Stopwatch2.Stop();
_ReactionTimes2.Add(_Stopwatch2.Elapsed);
labelSummary2.Text = String.Format("Player 2: Current: {0:0.000} s Minimum: {1:0.000} s Maximum: {2:0.000} s", _ReactionTimes2.Last().TotalSeconds, _ReactionTimes2.Min().TotalSeconds, _ReactionTimes2.Max().TotalSeconds);
}
else
{
_Stopwatch.Stop();
_ReactionTimes.Add(_Stopwatch.Elapsed);
labelSummary.Text = String.Format("Player 1: Current: {0:0.000} s Minimum: {1:0.000} s Maximum: {2:0.000} s", _ReactionTimes.Last().TotalSeconds, _ReactionTimes.Min().TotalSeconds, _ReactionTimes.Max().TotalSeconds);
}
}