我在我的意見徹底尋找在這個網站的答案,但不幸的是我還沒有找到任何或我只是看着它吮吸。如何引用來自不同形式的現有引用對象?
我有2個窗體和1個控制器類和1個模型類或數據類。另外,ControllerClass
有一個模型類的數組。
在Form1
我不喜歡這對控制器的引用:
ControllerClass control = new ControllerClass();
在Form2
我想從ControllerClass
我在Form1
稱爲參考。
到現在爲止我一直在做這樣的事情:
ControllerClass control = new ControllerClass();
在
Form2
,但這只是使ControllerClass
的新副本,這是不是對我很有幫助。
那麼我怎樣才能使用ControllerClass
,我在Form1
中實例化了Form2
?
http://stackoverflow.com/questions/2957388/passing-object-to-different-windows-forms,http://stackoverflow.com/questions/4887820/how-do-you-pass-an-object從表單1到表單2和回到表單1,http://stackoverflow.com/questions/1665533/communicate-between-two-windows-forms-in-c-sharp – Corak
只需將對象作爲Form2(Form2 f2 = new Form2(control);')的構造函數中的一個參數,或者創建一個公用屬性,然後填充對象引用。 –