When button clicked again do other action

3k Views Asked by At

So I am making a tool for PS3 however I need help on making a button do another action when clicked again, this is what I have but I am getting errors, thanks.

private void metroButton2_Click(object sender, EventArgs e)
    {
        byte[] On = new byte[] { 0x00 };
        PS3.SetMemory(0x007EDCA4, On);
    }
    else
    {
        byte[] On = new byte[] { 0x65 };
        PS3.SetMemory(0x007EDCA4, Off);
    }
1

There are 1 best solutions below

0
On

I see what you're trying to do but you can't use an else statement that way. The else keyword can only be used following an "if" statement. What you'll need is some kind of flag (a bool variable) which you switch between true and false to swap the button_click event's execution.

bool metroBtnFlag = true;
private void metroButton2_Click(object sender, EventArgs e)
{
   if (metroBtnFlag)
   {
       metroBtnFlag = false;
       //First, third, fifth, etc... click events
   }
   else
   {
      metroBtnFlag = true;
      //Second, fourth, sixth, etc... click events
   }
}

Alternatively, if you only want the button to do something the first time, and then do something different every other time, just remove one of the flag assignments. That way, when its set to false, it will never execute the first block of code again.