Accessing parent form variable from child form

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, ...)
 
F

Fabien Bezagu

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?
 
L

Ladislav Soukup

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?
 
G

Guest

You should really consider using event delegates and let FORM2 trigger an
event that FORM1 can then catch.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top