在我編寫的程序中,我想出了用戶控件的功能,因此我決定將它分解到它自己的項目/ DLL中。該控件由兩個按鈕和一個面板組成。但是,當我使用DLL時,我缺少一個關鍵的功能 - 我不能再更改面板的AutoScrollPosition
!我的直覺是,我得到一個副本,而不是一個參考屬性,當我去設置它...因此,這裏的代碼的一個想法:Winform用戶控件 - 如何獲取屬性的引用而不是副本
// this works when the user control is native to my project
panelContainer.AutoScrollPosition = new Point(0, myVal + 1);
// this doesn't work when the user control is Referenced in my project
FromDLL.panelContainer.AutoScrollPosition = new Point(0, myVal + 1);
我可以在FromDll.panelContainer
改變其他屬性,如名稱,但我無法更改AutoScrollPosition。兩者之間的其他屬性完全相同(AutoScroll = false
等)。最糟糕的是,當我在DLL創建setter方法,該呼叫:
// Call from project to set DLL's reference to native panel
FromDLL.SetMainPanel(nativePanel);
// Now this works after the call to SetMainPanel
FromDLL.panelContainer.AutoScrollPosition = new Point(0, myVal + 1);
爲什麼我會得到AutoScrollPosition而不是引用的副本任何想法?
panelContainer是一些贏的形式標準類或它是你的包裝? –
好問題 - panelContainer只是一個WinForms'Panel'。 – sorrell
FromDLL.panelContainer只是一個字段或屬性? –