【发布时间】:2015-12-20 05:27:24
【问题描述】:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Timers;
namespace SoftwareEngineering
{
public partial class MainGame : Form
{
private int tick = 60;
public MainGame()
{
InitializeComponent();
StartPosition = FormStartPosition.CenterScreen;
}
private void MainGame_Load(object sender, EventArgs e)
{
}
private void NewGame_Click(object sender, EventArgs e)
{
timer1.Tick += new EventHandler(timer1_Tick);
timer1.Start();
}
private void timer1_Tick(object sender, EventArgs e)
{
timeremaining.Text = tick + " Remaining";
if(tick > 0)
{
tick--;
}
else
{
timeremaining.Text = "Times Up!";
}
}
private void timeremaining_TextChanged(object sender, EventArgs e)
{
}
我的计时器有问题,当我启动程序时,计时器会自动倒计时而不按按钮,如果单击按钮计时器会减1。
示例: “56 Remaining”当我单击按钮时,计时器将递减,结果将是“54 Remaining”,依此类推。 (单击按钮)从“54 到 51”。
我该如何解决这个问题,请帮忙。
【问题讨论】:
-
您是否在计时器上将
Enabled设置为True?将其更改为False。 -
@Blorgbeard 甚至在我之前就给出了正确答案。我可能在打字时错过了它。他的回答值得称赞。
-
@vnikhil 但我很懒,只是发表了评论;你实际上花时间写了一个答案:你得到了信用:)
-
@Blorgbeard 如此谦虚(鞠躬)