2013-02-13 115 views
0

我正在研究一個從Form類繼承的類庫,然後在Gui應用程序中顯示這個表單。現在我需要將類庫改爲UserControl在WinForm中顯示UserControl

如何在另一個項目中的表單內顯示它?在此先感謝您的建議。

IFaceForm是InterfaceLibrary中的usercontrol。

using InterfaceLibrary; 

namespace MxlInterface 
{ 
    public partial class IFaceConn : Form 
    { 
     iFaceForm Interface = new iFaceForm(); 

     //size of the parent form is 881,514 
     //use these variables to change the position of the "Interface Form" 
     int xlocation = 0; 
     int ylocation = 0; 

     public IFaceConn() 
     { 
      InitializeComponent(); 

      //Interface.StartPosition = FormStartPosition.Manual; 
      Interface.Location = new Point(xlocation, ylocation); 
      //Interface.MdiParent = this; 

      Interface.Show(); 
     } 
    } 
} 
+0

請發佈任何您可能擁有的相關代碼。 – Brian 2013-02-13 18:46:37

+0

this.Controls.Add(Interface); – 2013-02-13 19:05:31

+0

感謝所有,比我想象的更容易:) – Art 2013-02-13 19:21:05

回答

4

你可以直接做類似的東西添加到窗體:

MyUserControl myControl = new MyUserControl(); 
Controls.Add(myControl); 

這也是經常有用放置Panel,可以爲您的表單上的用戶控件的佔位符,然後將用戶控件添加到該面板:

MyUserControl myControl = new MyUserControl(); 
myControlWrapperPannel.Controls.Add(myControl;