2013-05-17 120 views
0

我正在嘗試編寫不使用MS Designer的表單代碼。C#(Visual Studio 2010)未找到包含的參考

當我編譯,我一直得到同樣的錯誤:

類型System.ComponentModel *在未引用的程序集定義。

這將顯示IComponent,ISynchronizeInvoke和Component。我想我已經參考了它。

我嘗試刪除引用並重新應用它,並切換到早期版本的.net。它必須是我的環境中的東西,但我找不到它。

using System; 
using System.ComponentModel; 
using System.Windows.Forms; 


public class EmptyForm : System.Windows.Forms.Form 
{ 

    public EmptyForm() 
    { 
    } 
    public static int Main() 
    { 
     Application.Run(new EmptyForm()); 
     return 0; 
    } 
} 

Screen shot of my Visual Studio.

+0

'System.ComponentModel.Component'是**類型**,不是程序集。 'System.ComponentModel.Composition'與此無關。 – SLaks

+0

爲什麼要手動編寫Windows窗體(沒有設計者)? –

+0

@RyanGates有很多案例可以做到這一點,我經常使用的其中一個是動態表單創建。 – Magnum

回答

5

由於錯誤明確狀態,你需要添加一個引用到系統

+0

我想這可能會更方便用戶。 – deltree

+0

嗯我認爲「你必須添加一個參考系統」非常友好我的自我 –

3

要添加一個引用,只需右鍵點擊參考,選擇添加引用。您可以添加相關參考。

您有using指令,但您沒有引用程序集。

+0

hattenn有正確的答案。只需將系統參考添加到hattenn提供的說明中,然後放入'using System;' – Magnum

+0

@Magnum:實際上,'using'語句不是必需的;這些錯誤都不是關於命名空間的。 – SLaks