Return the hidden FORM from another FORM

I have two forms Form1 and Form2

I open Form2 from Form1 on button_Click

 Form2 obj2 = new Form2(); this.Visible = false; obj2.Show(); 

then I want to return Form1 Visible (when disposing Form2 ) in the same state of the controls that I left .....

+7
c # winforms
source share
2 answers

Your Form2 does not know anything about Form1 . He will need a link to it (you can do this by adding the Form type property to Form2 and assign it Form1 after construction):

 //In Form2 public Form RefToForm1 { get; set;} //In Form1 Form2 obj2 = new Form2(); obj2.RefToForm1 = this; this.Visible = false; obj2.Show(); //In Form2, where you need to show Form1: this.RefToForm1.Show(); 
+16
source share

A deferred response will work fine, another option with the same result will expose a public event in Form2, called, for example, β€œAfterClose”, call it when Form2 deletes, and have Form1 add an event handler where it is displayed. Let me know if you are interested, and I will give an example code.

0
source share

All Articles