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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 09:54:30  来源:igfitidea点击:

The type of namespace name 'Control' could not be found (are you missing a using directive or assembly reference?)

c#.net

提问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.dllin the System.Windows.Formsnamespace.

它位于System.Windows.Forms.dllSystem.Windows.Forms命名空间。

WPF:(probably not this one, because there's no relevant Controlsproperty in the WPF classes)

WPF:(可能不是这个,因为ControlsWPF 类中没有相关属性)

It's located PresentationFramework.dllin the System.Windows.Controlsnamespace.

它位于PresentationFramework.dllSystem.Windows.Controls命名空间。

Web Controls:

网页控制:

It's located System.Web.dllin the System.Web.UInamespace.

它位于System.Web.dllSystem.Web.UI命名空间。

回答by user20492

  1. Add the System.web.dll to refrence in solution explorer at right side.
  2. Add the namespace - System.Web.UI.WebControls; at the top of your web page.
  3. then you can create the web control by the coding itself.
  1. 将 System.web.dll 添加到右侧解决方案资源管理器中的引用。
  2. 添加命名空间 - System.Web.UI.WebControls; 在您的网页顶部。
  3. 然后您可以通过编码本身来创建 Web 控件。