重置计数

时间:2014-12-01 22:57:11

标签: c# count reset

我遇到的问题是当我点击停止时标签重置为零,但当我再次点击开始时,计数器会从最后一次停止的位置开始。我想在每次单击开始按钮时使计数器从零开始。这就是我所拥有的:

    //Perform mouse down followed by mouse up while counting the number of clicks performed.
    int Count = 0;
    private void PerformClick_Tick(object sender, EventArgs e)
    {
        Count++;
        CountTxt.Text = Count.ToString();
        mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
        mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);    
    }

    //Convert our text to int to control our timer speed.
    private void Speed_TextChanged(object sender, EventArgs e)
    {
        int SetSpeed = Int32.Parse(Speed.Text);
        PerformClick.Interval = SetSpeed; 
    }

    //Reset counter to zero after the program is stopped
    private void Reset_Tick(object sender, EventArgs e)
    {
        if (PerformClick.Enabled == false)
        {
            CountTxt.Text = "0";
        } 
    }

1 个答案:

答案 0 :(得分:3)

好像你忘记将Count变量重置为零。

尝试这样的事情:

private void Reset_Tick(object sender, EventArgs e)
{
    if (PerformClick.Enabled == false)
    {
        CountTxt.Text = "0";
        Count = 0;
    } 
}