2016-12-16 14 views
0

我的Windows窗體名稱叫「主登錄」無法從「BillingSystem.Presentation.MasterLogin」轉換爲「System.Windows.Forms.Form中」

public partial class MasterLogin : UserControl 

當我通過這種形式爲「Program.cs中」,這裏示出了象

錯誤1爲 最好重載方法匹配誤差 'System.Windows.Forms.Application.Run(System.Windows.Forms.Form中)' 具有 一些無效參數

我Program.cs中的代碼如下

using BillingSystem.Presentation; 
using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Threading.Tasks; 
using System.Windows.Forms; 
using BillingSystem.Reports; 


namespace BillingSystem 
{ 
    static class Program 
    { 
     /// <summary> 
     /// The main entry point for the application. 
     /// </summary> 
     [STAThread] 
     static void Main() 
     { 
      Application.EnableVisualStyles(); 
      Application.SetCompatibleTextRenderingDefault(false); 
      Application.Run(new MasterLogin()); //usercontrol ---Error here 

     } 

    } 
} 
+0

用戶控件無法作爲應用程序啓動。您可以將該控件放在窗體上(我們稱之爲'MasterLoginForm'),然後調用'Application.Run(new MasterLoginForm());' – Nino

+1

您需要一個表單而不是usercontrol來啓動應用程序。 – Maarten

+0

用戶控件存在於窗體中,應用程序啓動窗體。添加一個表單,將你的用戶控件添加到表單中,啓動表單。 – Liam

回答

1

您不能運行在一個WinForms應用程序的用戶控制,用戶控件是由表格寄載的控制。

這就是爲什麼Application.Run不允許你傳遞UserControl參數(因此你的編譯器錯誤),因爲它只會運行一個WinForm。

A 表格是一個可以顯示的窗口。

A 用戶控件是表單的可重用部分。當您想要以多種形式重複相同或類似的控制集時,或者創建一個不存在的控件時,它非常有用。

您必須將您的用戶控件添加到表單並顯示此表單。如果您不需要重複使用您的用戶控件,也可以將其內容直接添加到表單中(例如,如果控件只是一個文本框和一個標籤)。

+1

@ artman41:感謝編輯,我刪除了代碼部分,因爲它不足以創建表單並添加UC。表單需要重新調整大小,也許邊框樣式改變了等等。最好在設計師那裏做。 – Sefe

相關問題