2015-09-07 49 views
0

在我編寫的程序中,我想出了用戶控件的功能,因此我決定將它分解到它自己的項目/ 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而不是引用的副本任何想法?

+0

panelContainer是一些贏的形式標準類或它是你的包裝? –

+0

好問題 - panelContainer只是一個WinForms'Panel'。 – sorrell

+0

FromDLL.panelContainer只是一個字段或屬性? –

回答

-1

您需要檢查控制客戶端大小,而不是System.Windows.Forms.ScrollableControl.AutoScrollMinSize。此外,請確保您的System.Windows.Forms.ScrollableControl.AutoScroll是真實的,並考慮到System.Windows.Forms.ScrollableControl.AutoScrollMarginSystem.Windows.Forms.ScrollableControl.AutoScrollOffset。有可能你根本不理解這個概念,就像過去的一些成員一樣。

這是關於物質的極簡和明確解釋的文章: http://www.bobpowell.net/understanding_autoscroll.htm[ ^]。

另請參閱: http://msdn.microsoft.com/en-us/library/system.windows.forms.scrollablecontrol.aspx[ ^]。

相關問題