C# 找不到命名空间名称“Control”的类型(您是否缺少 using 指令或程序集引用?)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1169026/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
The type of namespace name 'Control' could not be found (are you missing a using directive or assembly reference?)
提问by flavour404
Trying to set up an extension method in .Net 3.0 using generics and I get an error message, details above on the line:
尝试使用泛型在 .Net 3.0 中设置扩展方法,我收到一条错误消息,上面有详细信息:
foreach(Control childControl in parent.Controls)
Am I missing a using directive or assembly reference?
我是否缺少 using 指令或程序集引用?
Thanks
谢谢
What I am trying to do is set this up (below) as an extender function:
我想要做的是将其设置(如下)作为扩展器功能:
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
namespace System.Runtime.CompilerServices
{
public static class ControlHelper
{
public static T FindControl<T>(this Control parent, string controlName) where T : Control
{
T found = parent.FindControl(controlName) as T;
if (found != null)
return found;
foreach (Control childControl in parent.Controls)
{
found = childControl.FindControl(controlName) as T;
if (found != null)
break;
}
return found;
}
}
}
I am missing a reference to the system.core.dll... its driving me nuts!
我缺少对 system.core.dll 的引用……这让我发疯了!
采纳答案by Sam Harwell
Choose the one for the technology you're using:
为您使用的技术选择一种:
Windows Forms:
Windows 窗体:
It's located in System.Windows.Forms.dll
in the System.Windows.Forms
namespace.
它位于System.Windows.Forms.dll
在System.Windows.Forms
命名空间。
WPF:(probably not this one, because there's no relevant Controls
property in the WPF classes)
WPF:(可能不是这个,因为Controls
WPF 类中没有相关属性)
It's located PresentationFramework.dll
in the System.Windows.Controls
namespace.
它位于PresentationFramework.dll
在System.Windows.Controls
命名空间。
Web Controls:
网页控制:
It's located System.Web.dll
in the System.Web.UI
namespace.
它位于System.Web.dll
在System.Web.UI
命名空间。
回答by user20492
- Add the System.web.dll to refrence in solution explorer at right side.
- Add the namespace - System.Web.UI.WebControls; at the top of your web page.
- then you can create the web control by the coding itself.
- 将 System.web.dll 添加到右侧解决方案资源管理器中的引用。
- 添加命名空间 - System.Web.UI.WebControls; 在您的网页顶部。
- 然后您可以通过编码本身来创建 Web 控件。