Accessing parent form variable from child form

  • Thread starter Thread starter Ladislav Soukup
  • Start date Start date
L

Ladislav Soukup

Hi,
I'm now migrating to C# and .NET 1.1 programming from PHP and PERL and I
have one problem and I cannot solve it (google didn't help).

I have two forms - FORM1 and FORM2

FORM1 will make instance of FORM2 and open it...

Code:
Form frm = new FORM2();
frm.Open();

Now... when Form2 is closing I need to change some variables in FORM1 and
call one public function in FORM1.
How can I do this? Should I make new instance of FORM1 in FORM2 code, or can
I make direct call from FORM2 to FORM1 variables and methods?

Please help...
Thanks for any response (link to article, ...)
 
Ladislav,

To solve your problem, you simply have to consider your forms like instances
(what of course they are) of classic classes.
To call methods on *the* form1 instance which created the closing form2
instance, you have to know it. One way is to pass its reference to the form2
constructor.

Fabien

I'm now migrating to C# and .NET 1.1 programming from PHP and PERL and I
have one problem and I cannot solve it (google didn't help).


Really ? Nevertheless, it's a recurrent problem...
I have two forms - FORM1 and FORM2

FORM1 will make instance of FORM2 and open it...

Code:
Form frm = new FORM2();
frm.Open();

Now... when Form2 is closing I need to change some variables in FORM1 and
call one public function in FORM1.
How can I do this? Should I make new instance of FORM1 in FORM2 code, or
can I make direct call from FORM2 to FORM1 variables and methods?
 
OK, It's working now :D
Thank You VERY much, You realy helped me.

----------------------------------
Ladislav Soukup
Radio CITY / Radio BLANÍK
246 046 159

Fabien Bezagu said:
Ladislav,

To solve your problem, you simply have to consider your forms like
instances (what of course they are) of classic classes.
To call methods on *the* form1 instance which created the closing form2
instance, you have to know it. One way is to pass its reference to the
form2 constructor.

Fabien

I'm now migrating to C# and .NET 1.1 programming from PHP and PERL and I
have one problem and I cannot solve it (google didn't help).


Really ? Nevertheless, it's a recurrent problem...
I have two forms - FORM1 and FORM2

FORM1 will make instance of FORM2 and open it...

Code:
Form frm = new FORM2();
frm.Open();

Now... when Form2 is closing I need to change some variables in FORM1 and
call one public function in FORM1.
How can I do this? Should I make new instance of FORM1 in FORM2 code, or
can I make direct call from FORM2 to FORM1 variables and methods?
 
You should really consider using event delegates and let FORM2 trigger an
event that FORM1 can then catch.
 
Back
Top