Darksly
Darksly

Reputation: 17

C++ Transferring Variable between Buttons

In My Code I want to Re-Use My buttons, Since I dont want to Deal with tons of them... But the Variables that I use to Change the Events of the buttons Are not Transferring... How would I make A variable Global enough so that If it is changed by one button, Say X = 1, It can be Used by another button, So X = 1 in that button as well? Here is my Code for the two buttons... int ^ YesOrNo Has already been initialized outside of the two buttons, making them accessible but not change-able by buttons...

private: System::Void button2_Click(System::Object^ sender, System::EventArgs^ e) {
this -> button4 -> Visible = true;
this -> button2 -> Visible = false;
this -> button5 -> Visible = true;
this -> button3 -> Visible = false;
this -> label2 -> Visible = true;
this -> label2 -> Text = "Are you Sure?";
YesOrNo = 1;
}

 private: System::Void button4_Click(System::Object^ sender, System::EventArgs^ e) {
  if (YesOrNo == 1)
  {
     this -> label2 -> Text = "To Make your Pony Character, See PonyMakin.txt in your... etc;                                                  
     button4 -> Text = "Show Pony";
     YesOrNo = 2;
  }
  else if (YesOrNo == 2)
  {
    this -> pictureBox3 -> Load("PonyCharacter.jpg");
  }
}

I have already Declared the int ^ YesOrNo; outside the two buttons, So both have access to it, But when one button changes YesOrNo to 1, The other button will still only see it as if were just initialized! I know that It is probably because both buttons are Void, But I don't know how to change those either...

Upvotes: 1

Views: 441

Answers (1)

qwr
qwr

Reputation: 3670

replace int^ with int . all will work . and see ^ its meaning from this link What does the caret (‘^’) mean in C++/CLI?

Upvotes: 1

Related Questions