I know that there is probably a very easy way to do this, but I have yet to figure it out. Here is the basic scenario:
Form1 contains Label1
Form1 creates an instance of Form2
Form2 contains Button1
Form2.Button1.onClick needs to set Form1.Label1.Text = "something" (without creating a new instance of Form1 because I need to keep all other values as-is).
I checked out your project and I think I discovered our differences. My project is a VB.NET project. I'm not sure if that is the cause of the differences or not (sorry for not making that clear earlier).
Wokawidget, is your code in VB6? .NET gave me an error about it no longer being supported. I tried to create something equivalent and it gave me null object errors when trying to set values in the form. I think it has something to do with how .NET uses "instances" of objects (i.e. I wasn't working with the actual form1, only an instance of it.)
This is really frustrating, something that seems so easy and trivial is turning out to be quite a pain. Anyone else have any ideas?
Search the VB.NET Forum for passing values across forms or something like that . There are couple of ways , one of them is to override the form's constructor passing a form as para . The other way , is to define global form variable . I'm not sure if you can do it with delegates . Sorry I can't think of that right now .
You could just have Searched in the " Windows Form Designer generated code " of your form1 for the declarationn of your label and, you could add the word "Shared" in the beginning of the declaration. This is what caused this error "Reference to a non-shared member requires an object reference."
- Use the thread tools to Mark your Thread as Resolved when your question is answered.
- Please Rate my answers if they where helpful.