im trying to make my main window open another window that i made (in the same project) by the press of a button.. and then i need the other window to give back all its info to the main window when done.. its a very simple app program im just trying to get the basics down.. anyhelp

opening a window
jcollake
asitkk
I'll give you my answer assuming that you're using c++/cli.
- Create 2 forms: Form1, Form2. (I guess you already did this)
- In the Form1 constructor create a Form2 instance:
#include "Form2.h"
ref class Form1 {
Form2^ form2;
Form1() {
// vs stuff here
this->form2 = gcnew Form2();
}
// other stuff here
};
- In the designer, choose Form1 and add a button to it.
- Double click on the button to add an event handler for the onclick event.
(This should take you to the method that the designer created.)
- Show the form2 created in the constructor:
// since it is already created, just show it
form2.Show();
Now, let's make sure not to destroy the instance of form2 when closing it.
- Open the designer and choose Form2 and go to the event handler's section (little lightning bolt in the properties tab)
- Add an event handler to the onclose event.
(This should take you to the method that the designer created.)
- In the method, hide the form but cancel the event to prevent the framework from disposing the form object.
this->Hide();
e->Cancel = true;
For the second part (returning values from Form2 to form1), you have some ways to do this and the "best" one depends on what type of data you want to send from one form to the other and how you're going to treat that data.
I can give you here a simple way of doing this:
Since you can access form2 from form1, just create properties to access the data in form2.
public: property int MyInt { int get() { return myInt; } }
Hope this helps.
TommK
if you created the forms using the VS wizards (through menus), just go to the file where you have Form1 (possibly Form1.cpp in the solution explorer), right click on it and choose: view source. There you find the constructor.
The "// vs stuff here" and "//other stuff there" is code that VS automatically generates when you create a form using the wizards. You'll see that when you do the other step (view source) that I described before.