2013-04-04 48 views
1

我想做的用戶控件如下:「類型或命名空間名稱找不到」在用戶控件

foreach(Control c in this.Controls) 
{ 
    if(c is CheckBox) 
    { 
     // Do stuff here 
    } 
} 

但我得到的錯誤:

Error 1 The type or namespace name 'Control' could not be found (are you missing a using directive or an assembly reference?)
Error 2 The type or namespace name 'CheckBox' could not be found (are you missing a using directive or an assembly reference?)

三江源指導。

+1

你看了錯誤消息System.Windows.Controls?它告訴你到底是什麼問題。您需要導入對應於'Control'和'Checkbox'的2個DLL。 – tnw 2013-04-04 13:52:10

+0

您是否導入了'System.Windows.Forms.Control'? – Joetjah 2013-04-04 13:51:14

回答

8

您忘記了包含System.Web.UI.WebControlsSystem.Windows.Forms(取決於您正在開發的應用程序的類型)與using指令。

+0

感謝您的幫助! – saam 2013-04-04 13:54:43

+0

@saam如果這個工作,然後請標記爲答案。 – 2013-04-04 13:55:33

+1

@PM我確定我會等7分鐘後 – saam 2013-04-04 13:57:11

1

您需要添加System.Windows.Forms.dll。

它位於System.Windows.Forms命名空間的System.Windows.Forms.dll中。

3

您應該添加任何System.Windows.Forms的,或System.Web.UI.WebControls,或取決於你用什麼技術

相關問題