Reputation: 636
I am using the winForm in Visual c++ to build my program. From the first window i need to move to another window on a button click. For this i am using the below code and it works fine.
private: System::Void button3_Click(Object^ sender, EventArgs^ e) {
this->Hide();
Form2^ pp = gcnew Form2();
pp->ShowDialog();
}
However i need a Back button on the child window which on click would hide/disable it and show the parent window. How can i achieve this?
Upvotes: 0
Views: 2066
Reputation: 1815
First of all if you want to do some navigation kind of things then, Your code of going parent to child is also not work properly.
Now what I suggest you is that for going from parent to child create one global variable. Like ,
Form2^ pp ;
initialise it in constructor or create method of parent class
Like,
//Create method or constructor,
pp = gcnew Form2();
And do your navigation Like,
private: System::Void button3_Click(System::Object^ sender, System::EventArgs^ e)
{
this->Hide();
pp->ShowDialog();
}
In this case no matter how many time you click on button3 only one instance of child class will show and hide.
No your problem is that you want go back to parent window form from child window. You may achieve this using this.Parent as Form
Like,
private: System::Void button3_Click(System::Object^ sender, System::EventArgs^ e)
{
this->Hide();
Form parentForm = (this.Parent as Form);
parentForm ->Show();
}
Upvotes: 1