-1

I have 3 forms. Form 1 has information inserted into Form 2. After clicking a button on Form 2 to get to Form 3; on Form 3 I pull data and put it on Form 2. The problem with this is that I don't know how to get a single instance of Form 2 so that I can keep the data from Form 1 after pulling data from Form 3. This is a WinForms application. Any help would be much appreciated. I have looked into the Singleton way of doing it but everything I research seems too confusing to follow. Thanks!

3
  • 2
    You don't need a Singleton. Maintain a reference member to the form from which you want to pull data. Form instances work just like any other object does. Jul 22, 2014 at 18:09
  • 1
    Pretty funny that the question was "closed as unclear what you're asking" after an answer was given which was later accepted with a "thank you!" from the OP.
    – GHP
    Sep 4, 2014 at 18:37

1 Answer 1

2

Forms are objects, so you can pass them into the constructor of each other form:

Class Form2{
Form form1;

Form Form2(Form form1){ // Constructor
this.form1 = form1;

} }

Now, you have a reference to the Form1 object in a field of Form2. If you need information, you use Form1.information

0

Not the answer you're looking for? Browse other questions tagged or ask your own question.