I have two forms that share data between eachother.

  1. In Designer view of Form2 I establish a public variable.

    public bool isMyFormValid

  2. When I attempt to access the variable in Form1 like this...

    if (Form2.isMyFormValid = true) { //do this}

C Sharp no likey... I get this message: Error 1 An object reference is required for the non-static field, method, or property 'WindowsFormsApplication1.Form2.isMyFormValid' C:\Users\tthompso\documents\visual studio 2010\Projects\practice\practice\Form1.cs 89 23 practice

Clearly there is a basic principal I'm not understanding. Can someone point me to a referece that explains this concept or provide a helpful example?

Your variable 'isMyFormValid' is an instance variable, meaning that you need to create a Form2 object and access it through that instance.

Momerath,
That was the approach I used to resolve my problem. In Form1 I initially called the Form2 by creating an object of the Form...

Form2 newForm2 = new form2();

So my problem was in Form1 I was attempting to access the variable using the Form name followed by a period than the variable.

Form2.boolVariable  //<--- Not a chance!

Using your suggestion I took the object I created of Form2 and accessed the varable using that instead. So far it looks like a solution to me. thanks

newForm2.boolBariable //<--- works fine

Edited 4 Years Ago by tet3828: more detail..

This question has already been answered. Start a new discussion instead.