How to make two frames work together in c++ (using visual studio 2013)

good night, im having an issue with trying to figure out this. i need to work with two frames, i've already managed to open a secondFrame from the mainFrame. However, i cant figure out how to get the data changed from the secondFrame to update the data on the mainFrame because i cant create a mainFram type object inside the secondFrame code for god knows what reason. I hope that someone can help to solve this issue. Thanks in advance.

1
2
3
4
5
private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
		apoyo = gcnew MyForm1();
		apoyo->Show();
		this->Hide();
	}


This is the code from the button im using, "apoyo" would be the secondFrame object created inside mainFrame code. The mainFrame should be shown again when the secondFrame is closed. i already opened the code for the FormClosing event btw.
Last edited on
The normal to pass data from one form to another is using properties or variables.
For example in your form MyForm1 declare:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
private:
    String^ m_Input;
  public:
    property String^ Input 
    {
      String^ get ()
      {
        return m_Input;
      }
      void set (String^ value)
      {
        m_Input = value;
      }
    }

In your main form you can access it like this:
1
2
3
4
5
6
7
8
System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) 
{
  apoyo = gcnew MyForm1();
  apoyo->Input = "Hello";
  apoyo->Show();
  // do sth with the input from apoyo
  this->Hide();
}
thank you so much. other question, if i want to program a button in MyForm1.h to return to the mainFrame, how can i do something like button1_Click if i'm not allowed to put inside the MyForm1 code someting like:

1
2
3
4
mainFrame::Show()
// or
mainFrame ^main = gcnew mainFrame();
main->Show();
;
Last edited on
If you call MyForm1 from mainFrame it will automatically return to mainFrame when MyForm1 closes.
Topic archived. No new replies allowed.