Hoang Minh
Hoang Minh

Reputation: 1220

How to dynamically add a label in a tab control

I have a class called GamesConsole and two forms - Form2 and Form3.

In Form2, I create an instance of GamesConsole named Invoice. After I have added all the values inside of the Invoice list, I pass it to Form3 so I can reference it there.

So far, in Form3 I create an object of GamesConsole called InvoiceRental:

// build an object of GamesConsole on Form3
GamesConsole InvoiceRental = new GamesConsole()

//build a function to return the value of InvoiceRental
public GamesConsole GetInvoice
{
    get { return InvoiceRental; }
    set { InvoiceRental = value; }
}

And on Form2, right after I create an instance of Form3, I attempt to call the function GetInvoice on Form3 to set it equal to the Invoice in Form2. However, it won't let me.

Would anyone tell me how to pass an object to the form? I've been using the above function to get all the data type (int, string, double...) and it's working fine, except this time.

Upvotes: 1

Views: 170

Answers (1)

emre nevayeshirazi
emre nevayeshirazi

Reputation: 19241

Change your GamesConsole class to public class.

Your GetInvoice property is defined as public and it holds a reference to GamesConsole instance.

Thus, GamesConsole class itself should also be public too, otherwise how would you access the properties of GamesConsole instance using GetInvoice property ?

Upvotes: 2

Related Questions