Want to Acess Same instance of previous form...

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sid103
    New Member
    • Feb 2008
    • 2

    Want to Acess Same instance of previous form...

    Hi All.

    Rightnow i m stuck C# code!!!

    Discription:

    1.Main form run.
    2.hide Main form and goto form1.
    3.form1 to form2.
    4.form2 to same instance of form1.
    5.Close form2.

    I am able to do till steps 3 & step 5.I stuck up at step 4.
  • Shashi Sadasivan
    Recognized Expert Top Contributor
    • Aug 2007
    • 1435

    #2
    Can you create a contructor in form2 which takes a Form Object?
    [CODE=cpp]class form2 : Form
    {
    private Form calledByForm
    public form2 (Form prevForm)
    {
    this.calledByFo rm = prevForm;
    }

    private CallPrevForm()
    {
    calledByForm.Sh ow();
    }
    }[/CODE]

    Comment

    • sid103
      New Member
      • Feb 2008
      • 2

      #3
      Thanks Shashi Sadasivan for rly,But still in this i get error on private Form calledByForm and private CallPrevForm().

      And I m Bit new to this C# lang,I have used this libs:

      using System;
      using System.Drawing;
      using System.Collecti ons;
      using System.Componen tModel;
      using System.Windows. Forms;

      Comment

      • Shashi Sadasivan
        Recognized Expert Top Contributor
        • Aug 2007
        • 1435

        #4
        Originally posted by sid103
        Thanks Shashi Sadasivan for rly,But still in this i get error on private Form calledByForm and private CallPrevForm().
        Well, I am not sure how you are generating this error, maybe if you pasted the code from where the error is generating would be a great idea, especially when you consider yourself to be new to this.

        What I presume is that you are calling the method and attribute from form 1

        If that is the case then when you are instantiating form2 from form1

        you should be doing something similar to the foll
        Code:
        form2 frm2 = new form2(this);
        and the method CallPrevForm() is supposed to be called from form2, if you want form1 to call it then make it public

        Comment

        • r035198x
          MVP
          • Sep 2006
          • 13225

          #5
          Originally posted by sid103
          Hi All.

          Rightnow i m stuck C# code!!!

          Discription:

          1.Main form run.
          2.hide Main form and goto form1.
          3.form1 to form2.
          4.form2 to same instance of form1.
          5.Close form2.

          I am able to do till steps 3 & step 5.I stuck up at step 4.
          This is a common problem posted in this forum. The reason why most people run into this problem unfortunately is poor program design. Forms do not drive a program and should not be the first components of a program. Forms are only one possible input/output platform and should be designed last. Program design should instead be done using objects.

          Comment

          Working...