在UserControl中找不到“类型或命名空间名称”

时间:2013-04-04 13:49:15

标签: c# user-controls controls

我想在UserControl中执行以下操作:

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

但是我得到了错误:

  

错误1找不到类型或命名空间名称“Control”(您是否缺少using指令或程序集引用?)
  错误2找不到类型或命名空间名称'CheckBox'(您是否缺少using指令或程序集引用?)

谢谢你的指导。

4 个答案:

答案 0 :(得分:8)

您忘记使用System.Web.UI.WebControls指令包含System.Windows.Formsusing(取决于您正在开发的应用的类型)。

答案 1 :(得分:3)

您应该添加System.Windows.Forms,或System.Web.UI.WebControls或System.Windows.Controls,具体取决于您使用的技术

答案 2 :(得分:2)

您需要为System.Windows.Forms类添加Control名称空间,其中包含 System.Windows.Forms.dll

此外,您还需要为System.Web.UI.WebControls类添加Checkbox名称空间,其中包含 System.Web.dll

像;

using System.Windows.Forms;
using System.Web.UI.WebControls;

答案 3 :(得分:1)

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

它位于System.Windows.Forms命名空间中的System.Windows.Forms.dll