Answered How do you use an instance of a class on multiple forms?

Robawtic

New member
Joined
Aug 29, 2011
Messages
3
Programming Experience
1-3
I don't know how to do this and I've googled this to death so I was wondering if anyone could help me out.
 
Last edited:
This is a question that is often asked but those who ask it already invariably know the answer. They are just trying to turn something simple into something difficult.

Let's say that you have a TextBox and a Label on a form. How would you display the text entered by the user into the TextBox on the Label? You would get the Text property of the TextBox and assign it to the Text property of the Label, right? Congratualtions! You just shared an instance of a class amongst three controls: the TextBox, the form and the Label all made use of the same String object. All you had to do was get and set a property.

The answer to your question is exactly the same: one form simply has to assign your object to a property of the other form. You would have to declare the property yourself, but it's still just a property, just like the Text of a Button or TextBox.
 
Back
Top