.NET组件编程(1) 基础
注册blog已经很长一段时间了,但是却一篇文章都没有写过。想想也很惭愧,于是有了想写点东西的冲动。
介绍下我的工作,公司主要是开发第三方组件(Component)、控件(Control),我看园子里的朋友们写这方面不是很多(也许是我没有看到),所以打算写个关于组件开发的系列文章。
首先介绍基本知识,有很多的朋友搞不清楚Component与Control之间的区别,比较简单形象的区别有下面两点:
1、Component在Run Time时不能呈现UI,而Control可以在Run Time时呈现UI(但是vs 2005里的asp.net中的SqlDataSource是Control,但是它不能呈现UI)。
2、Component是贴在容器Container上的,而Control则是贴在Windows Form或者Web Form上的。
举例来说,SqlCommand是个Component,DataGrid则是一个Control。
那我们又如何来开发一个Component呢?其实很简单,只要我们把一个类从System.ComponentModel.Component(下面简写Component)继承下来即可
。
下面我们就来编写一个简单的Component,打开vs 2005添加一个新的ClassLibrary工程,名称为Components,更改Class1的代码如下:

































编译完成后,其Property的效果如下:
请注意Id是灰色,不能对其进行设值,而CreateDateTime在Property窗口中没有显示。
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 一个奇形怪状的面试题:Bean中的CHM要不要加volatile?
· [.NET]调用本地 Deepseek 模型
· 一个费力不讨好的项目,让我损失了近一半的绩效!
· .NET Core 托管堆内存泄露/CPU异常的常见思路
· PostgreSQL 和 SQL Server 在统计信息维护中的关键差异
· CSnakes vs Python.NET:高效嵌入与灵活互通的跨语言方案对比
· DeepSeek “源神”启动!「GitHub 热点速览」
· 我与微信审核的“相爱相杀”看个人小程序副业
· Plotly.NET 一个为 .NET 打造的强大开源交互式图表库
· 上周热点回顾(2.17-2.23)