title: Toggle a button's text from "On" to "Off" when clicked (Visual C++)
body: <p>I was given a small task to simply make a button's text toggle "On" and "Off" when you clicked on it - it already starts with the text "Off" as it hasn't been pressed yet, but when you click it changes to "On". On each alternating click afterwards, the button's text would ideally keep changing from "On" to "Off". In my case I thought a simple boolean variable would be the solution as On and Off can be treated as True or False, but not to be...</p>
  
  <p>Anyway here's the code for the button's handler I've got so far:</p>
  
  <pre><code>private: System::Void toggleButtonText_Click(System::Object^  sender, System::EventArgs^  e) 
      {
        static bool isOn = true;
        if(isOn == false)
        {
         toggleButtonText-&gt;Text = "Off";
  
        }
        else
        {
        toggleButtonText-&gt;Text = "On";
        }
  
  }
  </code></pre>
  
  <p>As you can see, the name of the button is "toggleButtonText". In the InitializeComponent(void) method, this line enables the default text to "Off": </p>
  
  <pre><code>this-&gt;toggleButtonText-&gt;Text = L"On";
  </code></pre>
  
  <p>Looking at the rest of my tasks, getting this right will give me enough clues to attempt them on my own instead of spending ages on endless Google searches.</p>