我正在制作一个程序,其中 timer1 应该激活另一个 timer2 然后停止,在 timer2 中我再次激活 timer1 并停止 timer2 等等它继续,然后我有一个文本日志,它写下进度。这就是问题所在,首先它从 Timer1 的 2 记号开始,然后是计时器 2 的 2,然后乘以 2,所以下一次是 4,然后是 8,然后是 16,依此类推,我只希望它是 1 timer1 而不是 1 timer2然后它重新开始,我看不出有什么问题。
private void buttonStart_Click(object sender, EventArgs e)
{
buttonStart.Enabled = false;
buttonStop.Enabled = true;
timer1.Tick += new EventHandler(timer1_Tick);
timer1.Interval = (1000);
timer1.Enabled = true;
timer1.Start();
}
private void buttonStop_Click(object sender, EventArgs e)
{
buttonStart.Enabled = true;
buttonStop.Enabled = false;
timer1.Stop();
timer2.Stop();
}
private void LogWrite(string txt)
{
textBoxCombatLog.AppendText(txt + Environment.NewLine);
textBoxCombatLog.SelectionStart = textBoxCombatLog.Text.Length;
}
private void timer1_Tick(object sender, EventArgs e)
{
LogWrite(TimeDate + "player hit");
timer1.Stop();
timer2.Tick += new EventHandler(timer2_Tick);
timer2.Interval = (1000);
timer2.Enabled = true;
timer2.Start();
}
private void timer2_Tick(object sender, EventArgs e)
{
LogWrite(TimeDate + "mob hit");
timer2.Stop();
timer1.Tick += new EventHandler(timer1_Tick);
timer1.Interval = (1000);
timer1.Enabled = true;
timer1.Start();
}