下面我们就来编写一个简单的Component,打开vs 2005添加一个新的ClassLibrary工程,名称为Components,更改Class1的代码如下:using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel;namespace Components
{
    public class Component1 : Component
    {
        private int _id;
        private string _name;
        private DateTime _createDateTime;    // 在Property窗口中为灰色显示。
        public int Id
        {
            get { return _id; }
        }    // 在Property窗口中可以设置值。
        public string name
        {
            get { return _name; }
            set { _name = value; }
        }    // 在Property窗口中不可见。
        public DateTime CreateDateTime
        {
            set { _createDateTime = value; }
        }
    }
}生成后,我又新建了一个Web项目,然后引用了生成的组件,并且在工具箱中新建的卡,把那组件给引用了,那个组件出现在工具箱中,可是是灰色的,用不了不知道为什么希望高手给说说,我哪作错了,我是VS2008

解决方案 »

  1.   

    Id 是只读的, 当然是灰色了CreateDateTime, 只可写, 不可读, 属性编辑器怎么显示
      

  2.   

    http://www.cnblogs.com/mapserver/articles/343632.html
    文章在这里,说是最基础的了
      

  3.   

    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.ComponentModel;namespace Components
    {
        public class Atest : Component
        {
            private int _id;
            private string _name;
            private DateTime _createDateTime;        // 在Property窗口中为灰色显示。
            public int Id
            {
                get { return _id; }
                set { _id = value; }
            }        // 在Property窗口中可以设置值。
            public string name
            {
                get { return _name; }
                set { _name = value; }
            }        // 在Property窗口中不可见。
            public DateTime CreateDateTime
            {
                get { return _createDateTime; }
                set { _createDateTime = value; }
            }
        }
    }
    我改成这样的了,也没用哦
      

  4.   

    不好意思, 看错.winform, 2.0, 2005 是可以的
      

  5.   

    應該是framework的問題 你改下試試看
      

  6.   

    右擊網狀站
    屬性頁
    建置
    目標framework
      

  7.   


    设的是.net framework 3.5    输出类型是  类库
      

  8.   

    http://www.cnblogs.com/raycheung/archive/2006/03/22/356172.html
    看了你就会发现是用在winform里的
      

  9.   

    一般在Web应用程序中,如果需要一个组件没有界面,一般继承自System.Web.UI.Control,否则可以考虑继承自System.Web.UI.WebControls.WebControl,而在Web应用程序中继承自System.ComponentModel.Component,我从未用过
      

  10.   

    http://msdn.microsoft.com/zh-cn/library/system.web.ui.control(VS.80).aspx
    这是在开发自定义 ASP.NET 服务器控件时作为派生源的主要类。Control 没有任何针对用户界面 (UI) 的功能。如果创作没有 UI 的控件或者组合其他呈现它们自己的 UI 的控件,则从 Control 派生。如果创作具有 UI 的控件,则从 WebControl 或 System.Web.UI.WebControls 命名空间中的任何控件派生,该命名空间为自定义控件提供适当的起点。
      

  11.   

    也觉得应该是在winform里用的,你应该是没用对地方吧……
      

  12.   

    忽然感觉很有意思, 为啥不从 component 继承.
    楼主的被灰色掉, 应该是 rootdesigner 对工具栏设置了 ToolboxItemFilter 方面的属性
      

  13.   

    control,webcontrol,compositecontrol这三个不是开发控件时用的吗?
    System.ComponentModel.Component这个是开发组件用的。难道组件是在WinForm中用的?不对哦?WebFomr中也有组件哦?哪位明白给讲讲哦
      

  14.   

    asp.net 的设计时支持上, 微软很变态, 都做到了 vs 中. 鄙视一下.
      

  15.   

    很希望买您的新书,但我发现一个问题哦,庖丁解牛-Asp.net 3.5控件和组件开发技术 书名是讲开发“控件”与“组件”的吧,可是我上网查了目录,书里只讲了如何开发控件,根本没讲开发“组件”的事哦,请你说说,到底书里讲没讲“组件”部分?
    庖丁解牛-Asp.net 3.5控件和组件开发技术中也只看到讲控件部分,难道控件==组件?希望高手给讲讲哦
      

  16.   

    Visual Studio对于Web项目不支持将Component直接拖到IDE里面吧,你在后台代码中实例化你的组件试试
      

  17.   


    Namespace: System.Web.UI
    Assembly: System.Web (in system.web.dll)
    [ThemeableAttribute(false)] 
    [BindableAttribute(true)] 
    public class Control : IComponent, IDisposable, IParserAccessor, 
    IUrlResolutionService, IDataBindingsAccessor, IControlBuilderAccessor, IControlDesignerAccessor, IExpressionsAccessor
     
    它作为 web 体系下, 单独实现了 IComponent 接口, 可以认为是 web 体系下的 Component.
    我想还是跟设计时有关, winform/webform 需要截然不同的两个设计时架构.
      

  18.   


    呵呵,本来在Web上开发组件的就不多,至少我就没怎么见过,大部分人都是开发控件的
    毕竟c/s与b/s还是不一样的
      

  19.   


    我觉得Web不支持组件拖放,最大的原因就是,Web上的元素都是用标签来表示的,而这些元素都是继承自System.Web.UI.Control或System.Web.UI.WebControls.WebControl,他们通过Render事件可以在html中生成相应的html标签,如果是Component,估计做不到这一点吧
      

  20.   


    SqlDataSource一类的控件也没有Render出标签哦,这真的很难理解,微软就是不起平道
      

  21.   

    怎么大家都没看到 
    public class Control : IComponent, 呢
      

  22.   

    System.ComponentModel.Component实现了IComponent接口和MarshalByRefObject类,这都不是不在WEBform中不显示的原因吧。真正的原因只有超级高手能明白,还有微软开发组中的人能明白吧。真是白白花了4个小时