I want my code to close the current form and open another form without closing the application (in Visual C++ 2010 Express). Here’s the code I’m trying to use:
Form2^ form2=gcnew Form2();
form2->Show();
this->Close();
The application should be closed when all forms have been closed, so this->Hide() won’t work.
Open the main .cpp source code file in your project, the one that contains the main() function. You’ll see a statement in that function similar to this:
This overload of the Run() method will cause the program to terminate when the main form of app closes. If you want to keep it running then you’ll need to do this differently. Like using the plain Run() overload and call Application::Exit() when all of the windows are closed. You can do so by subscribing the FormClosed event, like this: