重置计数
本文关键字: | 更新日期: 2023-09-27 18:32:53
我遇到的问题是当我单击停止时,标签重置为零,但当我再次单击开始时,计数器从上次停止的地方开始。我想每次单击开始按钮时使计数器从零开始。这是我所拥有的:
//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";
}
}
似乎您忘记将 Count 变量重置为零。
尝试这样的事情:
private void Reset_Tick(object sender, EventArgs e)
{
if (PerformClick.Enabled == false)
{
CountTxt.Text = "0";
Count = 0;
}
}