0

我有一个你必须点击的按钮,它可以测量反应时间。在 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);
    }
}
4

2 回答 2

1

您正在使用_ReactionTimesList 来填充两个标签,而不是使用_ReactionTimes2for 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);
于 2013-11-01T12:11:33.710 回答
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);
    }
}
于 2013-11-01T12:14:13.193 回答