Accessing parent form variable from child form

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ladislav Soukup

    Accessing parent form variable from child form

    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 Soukup
    Radio CITY / Radio BLANÍK
    246 046 159


  • Fabien Bezagu

    #2
    Re: Accessing parent form variable from child form

    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

    [color=blue]
    > 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).[/color]


    Really ? Nevertheless, it's a recurrent problem...
    [color=blue]
    >
    > 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?
    >[/color]



    Comment

    • Ladislav Soukup

      #3
      Re: Accessing parent form variable from child form

      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" <fbezagu_at_nov acor_dot_fr> pí¹e v diskusním pøíspìvku
      news:%23pbFeCpk FHA.3144@TK2MSF TNGP12.phx.gbl. ..[color=blue]
      > 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
      >
      >[color=green]
      >> 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).[/color]
      >
      >
      > Really ? Nevertheless, it's a recurrent problem...
      >[color=green]
      >>
      >> 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?
      >>[/color]
      >
      >
      >[/color]


      Comment

      • Anders Tornblad, SPCS, Sweden

        #4
        RE: Accessing parent form variable from child form

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



        --
        // Anders Tornblad, Systems Developer at SPCS, Sweden


        "Ladislav Soukup" wrote:
        [color=blue]
        > 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 Soukup
        > Radio CITY / Radio BLANÍK
        > 246 046 159
        >
        >
        >[/color]

        Comment

        Working...