【发布时间】:2017-01-28 13:00:19
【问题描述】:
我一直在尝试多次尝试使这个 sn-p 代码工作,但我找不到解决方案。这里是:
private void buttonTwo_Click(object sender, EventArgs e)
{
sayingTwo.Visible = true;
buttonTwo.Text = "Click To Hide Saying";
buttonTwo.Click += new EventHandler(buttonTwo_Click2);
}
System.Windows.Forms.Timer tm2 = new System.Windows.Forms.Timer();
private void buttonTwo_Click2(object sender, EventArgs e)
{
if(sayingTwo.Visible == true)
{
buttonTwo .Enabled = false;
sayingTwo.Visible = false;
buttonTwo.Text = "Reactivating in 5 seconds";
tm2.Interval = (1000);
tm2.Tick += new EventHandler(timer2_Tick);
tm2.Enabled = true;
}
}
int ii = 4;
private void timer2_Tick(object sender, EventArgs e)
{
while (ii != 0)
{
buttonTwo.Text = "Reactivating in " + ii + " seconds";
ii -= 1;
}
if (ii == 0)
{
ii += 4;
tm2.Enabled = false;
buttonTwo.Enabled = true;
}
}
到目前为止,代码将执行以下操作:单击按钮时,将出现 saying/label。按钮的名称将更改为"Click To Hide Saying"。再次点击时,标签会消失,文字会显示"Reactivating in (ii) seconds"(ii是重新激活的剩余时间)。
我想要它做的是在ii = 0 (或按钮延迟到时)返回buttonTwo_Click 事件。如果您有解决此问题的方法或其他方法,我将不胜感激。
【问题讨论】:
-
如何在
Tick事件处理程序的开头停止计时器并在最后重新启动它? -
@UweKeim 我认为计时器是问题所在。它是事件处理程序的链接。这有帮助吗?