Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

get back hidden FORM from another FORM

Tags:

c#

.net

winforms

I have two forms Form1 and Form2

I am opening Form2 from Form1 on button_Click

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

then I want to get back Form1 Visible (on disposing Form2) in same states of Controls on which I left.....

like image 472
Javed Akram Avatar asked Nov 08 '10 11:11

Javed Akram


1 Answers

Your Form2 doesn't know anything about Form1. It will need a reference to it (you can do that by adding a Form type property on Form2 and assign Form1 to it 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();
like image 129
Oded Avatar answered Oct 13 '22 17:10

Oded