简体   繁体   English

如何在标签控件中动态添加标签

[英]How to dynamically add a label in a tab control

I have a class called GamesConsole and two forms - Form2 and Form3. 我有一个名为GamesConsole的类,并且有两种形式-Form2和Form3。

In Form2, I create an instance of GamesConsole named Invoice. 在Form2中,我创建了一个名为Invoice的GamesConsole实例。 After I have added all the values inside of the Invoice list, I pass it to Form3 so I can reference it there. 在“发票”列表中添加所有值之后,将其传递给Form3,以便可以在其中引用它。

So far, in Form3 I create an object of GamesConsole called InvoiceRental: 到目前为止,在Form3中,我创建了一个名为InvoiceRental的GamesConsole对象:

// 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. 在Form2上,在创建Form3实例之后,我立即尝试在Form3上调用函数GetInvoice,以使其等于Form2中的Invoice。 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. 我一直在使用上面的函数来获取所有数据类型(int,string,double ...),并且工作正常,除了这次。

Change your GamesConsole class to public class. 将您的GamesConsole类更改为公共类。

Your GetInvoice property is defined as public and it holds a reference to GamesConsole instance. 您的GetInvoice属性定义为public,并且它包含对GamesConsole实例的引用。

Thus, GamesConsole class itself should also be public too, otherwise how would you access the properties of GamesConsole instance using GetInvoice property ? 因此, GamesConsole类本身也应该是公共的,否则您将如何使用GetInvoice属性访问GamesConsole实例的属性?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM