I am creating an application where the front end has to be a Windows Form using C++/CLI. The form is used for login purpose.
In my form, I have a register button. On
Create a constructor for RegisterForm
which accepts a System::Windows::Form ^
object, and pass this
to it when you are instantiating it from within the login form class
Form^ rgForm = gcnew RegisterForm(this);
rgForm->Show();
this->Hide();
Assume the login form object is called otherform
within the RegisterForm class. Once you're ready to bring it back, just call otherform->Show()
When you hide the form, it still exists, it is just not visible to the user.
EDIT: I got this to work just fine. Here are the modifications (not the full code) that I made to the form
Form2(Registration form)
Form2(System::Windows::Forms::Form ^ frm1)
{
otherform = frm1;
InitializeComponent();
}
private: System::Windows::Forms::Form ^ otherform;
private: System::Void Cancel_Click(System::Object^ sender, System::EventArgs^ e) {
this->Hide();
otherform->Show();
}
Form1(Login form)
#include "Form2.h"
private: System::Void Register_Click(System::Object^ sender, System::EventArgs^ e) {
Form2 ^ frm2 = gcnew Form2(this);
frm2->Show();
this->Hide();
}