2013-05-14 77 views
1

我有一個名爲GamesConsole的類和兩個窗體 - Form2和Form3。如何在選項卡控件中動態添加標籤

在Form2中,我創建了一個名爲Invoice的GamesConsole實例。在我添加了Invoice列表中的所有值後,我將它傳遞給Form3,以便我可以在那裏引用它。

到目前爲止,Form3創建GamesConsole的對象調用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; } 
} 

而且Form2上,之後我創建Form3的一個實例,我試圖呼籲Form3功能GetInvoice進行設置等於Form2中的發票。但是,它不會讓我。

有人會告訴我如何將一個對象傳遞給窗體嗎?我一直在使用上面的函數來獲取所有的數據類型(int,string,double ...),並且它工作正常,除了這一次。

+0

當您嘗試設置GetInvoice時會出現什麼錯誤? –

+0

它表示不一致的可訪問性:屬性類型'Games_R_Us.GamesConsole'比屬性'Games_R_Us.frmYourCart.GetInvoice' –

回答

2

將您的GamesConsole類更改爲公共類。

您的GetInvoice屬性被定義爲public並且它擁有對GamesConsole實例的引用。

因此,GamesConsole類本身也應該公開,否則如何使用GetInvoice屬性訪問GamesConsole實例的屬性?

+1

更難以訪問。非常感謝你的幫助。 –

+0

很高興我能幫到你。如果你能標記我的答案是正確的,我會很高興。 –

+0

再次感謝;) –

相關問題