定时器仅在单击按钮并且传递if语句时滴答

时间:2017-04-16 22:48:55

标签: c#

我是编码的新手,我正在制作一个简单的点击游戏,并将计时器设置为每秒打勾,并在程序启动后启动。但是,没有任何事情发生,它只在单击一个按钮并传递if语句时打勾。有关如何解决此问题的任何帮助?我只包含一个按钮,但其余功能类似。

private void timer1_Tick(object sender, EventArgs e)
{
    clicks = clicks + (clicker1clicks * clicker1count) + (clicker2clicks * clicker2count) + (clicker3clicks * clicker3count) + (clicker4clicks * clicker4count) + (clicker5clicks * clicker5count);
}

private void button1_Click(object sender, EventArgs e)
{
    clicks = clicks + (1 * clickMultiplier);
    string clicksString = clicks.ToString() + clicksText;
    textBox1.ReadOnly = true;
    textBox1.Text = clicksString;

1 个答案:

答案 0 :(得分:0)

我相信您希望在UI中更新计时器滴答时看到计算值。

以下片段应该这样做。

private void timer1_Tick(object sender, EventArgs e) {
  clicks = clicks + (clicker1clicks * clicker1count) + (clicker2clicks * clicker2count) + (clicker3clicks * clicker3count) + (clicker4clicks * clicker4count) + (clicker5clicks * clicker5count);
  textBox1.ReadOnly = true;
  textBox1.Text = clicksString;
}