如何从已包含文本的标签中减去数字

时间:2015-08-18 19:10:57

标签: c#

enemyHP.Text =" Enemy HP:" + rat.HP.ToString();

我怎么办,因为我有文字。我只是想这样做,每一秒它都会下降一个。

    private void battleButton_Click(object sender, EventArgs e)
    {
        if (battleDropBox.SelectedItem.ToString() == "Rat")
        {
            enemyHP.Text = "Enemy HP: " + rat.HP.ToString();
            enemyDPS.Text = "Enemy DPS: " + rat.Damage.ToString();


            timer.Tick += new EventHandler(timer1_Tick);
            timer.Interval = 1000;
            timer.Start();
        }
    }

    private void timer1_Tick(object sender, EventArgs e)
    {
        dealDamage();
    }

    public void dealDamage()
    {
    }

1 个答案:

答案 0 :(得分:2)

您应该减少rat.HP值,然后更新标签。

public void dealDamage()
{
    rat.HP--;
    enemyHP.Text = "Enemy HP: " + rat.HP.ToString();
}