Home > OS >  increment by 2 instead of 1 after button is clicked
increment by 2 instead of 1 after button is clicked

Time:08-06

This is my code

int Moneycount;
        private void mButton_Click(object sender, EventArgs e)
        {
            Moneycount  ;
            MoneyCount.Text = Moneycount.ToString();
        }
        private void level1_Click(object sender, EventArgs e)
        {
        }

"mButton" is incremented by 1 every time I press it,

so I want it to be incremented by 2 instead of 1 after I press "level1"

CodePudding user response:

So if I understand you correctly, you want mButton to increment MoneyCount by one every time you press it. But after pressing level1, mButton should increment by 2 instead.

Try this:

int Moneycount;
int amountToIncrement = 1;
private void mButton_Click(object sender, EventArgs e)
{
    Moneycount  = amountToIncrement;
    MoneyCount.Text = Moneycount.ToString();
}
private void level1_Click(object sender, EventArgs e)
{
    amountToIncrement = 2;
}

CodePudding user response:

Try

Moneycount  = 2;

this increments by two

  • Related